d3drm: Implement object name property.
[wine.git] / dlls / d3drm / tests / d3drm.c
blob82e0166acbbc6745eceb76ebc7d6283091dc3ad2
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 HRESULT hr;
100 DWORD size;
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 = 1;
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 == 1, "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 todo;
1468 tests[] =
1470 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice, FALSE },
1471 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice2, FALSE },
1472 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice3, FALSE },
1473 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMWinDevice, FALSE },
1474 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture, FALSE },
1475 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture2, FALSE },
1476 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture3, FALSE },
1477 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport, FALSE },
1478 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport2, FALSE },
1479 { &CLSID_CDirect3DRMFace, &IID_IDirect3DRMFace },
1480 { &CLSID_CDirect3DRMFace, &IID_IDirect3DRMFace2 },
1481 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder },
1482 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder2 },
1483 { &CLSID_CDirect3DRMMeshBuilder, &IID_IDirect3DRMMeshBuilder3 },
1484 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame },
1485 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame2 },
1486 { &CLSID_CDirect3DRMFrame, &IID_IDirect3DRMFrame3 },
1487 { &CLSID_CDirect3DRMLight, &IID_IDirect3DRMLight },
1488 { &CLSID_CDirect3DRMMaterial, &IID_IDirect3DRMMaterial },
1489 { &CLSID_CDirect3DRMMaterial, &IID_IDirect3DRMMaterial2 },
1491 IDirect3DRM *d3drm1;
1492 IDirect3DRM2 *d3drm2;
1493 IDirect3DRM3 *d3drm3;
1494 IUnknown *unknown = (IUnknown *)0xdeadbeef;
1495 HRESULT hr;
1496 ULONG ref1, ref2, ref3, ref4;
1497 int i;
1499 hr = Direct3DRMCreate(&d3drm1);
1500 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
1501 ref1 = get_refcount((IUnknown *)d3drm1);
1502 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1503 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
1504 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1505 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
1507 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_DirectDraw, NULL, &IID_IDirectDraw, (void **)&unknown);
1508 ok(hr == CLASSFACTORY_E_FIRST, "Expected hr == CLASSFACTORY_E_FIRST, got %#x.\n", hr);
1509 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1511 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1513 BOOL takes_ref = IsEqualGUID(tests[i].clsid, &CLSID_CDirect3DRMMeshBuilder) ||
1514 IsEqualGUID(tests[i].clsid, &CLSID_CDirect3DRMFrame) ||
1515 IsEqualGUID(tests[i].clsid, &CLSID_CDirect3DRMLight) ||
1516 IsEqualGUID(tests[i].clsid, &CLSID_CDirect3DRMMaterial);
1518 unknown = (IUnknown *)0xdeadbeef;
1519 hr = IDirect3DRM_CreateObject(d3drm1, NULL, NULL, tests[i].iid, (void **)&unknown);
1520 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1521 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1522 unknown = (IUnknown *)0xdeadbeef;
1523 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, (void **)&unknown);
1524 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1525 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1526 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, NULL);
1527 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1529 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1530 todo_wine_if(tests[i].todo)
1531 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1532 if (SUCCEEDED(hr))
1534 ref2 = get_refcount((IUnknown *)d3drm1);
1535 if (takes_ref)
1536 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1537 else
1538 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1540 ref3 = get_refcount((IUnknown *)d3drm2);
1541 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1542 ref4 = get_refcount((IUnknown *)d3drm3);
1543 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1544 IUnknown_Release(unknown);
1545 ref2 = get_refcount((IUnknown *)d3drm1);
1546 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1547 ref3 = get_refcount((IUnknown *)d3drm2);
1548 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1549 ref4 = get_refcount((IUnknown *)d3drm3);
1550 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1552 /* test Add/Destroy callbacks */
1553 test_destroy_callback(i, tests[i].clsid, tests[i].iid);
1555 hr = IDirect3DRM2_CreateObject(d3drm2, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1556 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1557 ref2 = get_refcount((IUnknown *)d3drm1);
1558 if (takes_ref)
1559 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1560 else
1561 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1562 ref3 = get_refcount((IUnknown *)d3drm2);
1563 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1564 ref4 = get_refcount((IUnknown *)d3drm3);
1565 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1566 IUnknown_Release(unknown);
1567 ref2 = get_refcount((IUnknown *)d3drm1);
1568 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1569 ref3 = get_refcount((IUnknown *)d3drm2);
1570 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1571 ref4 = get_refcount((IUnknown *)d3drm3);
1572 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1574 hr = IDirect3DRM3_CreateObject(d3drm3, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1575 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1576 ref2 = get_refcount((IUnknown *)d3drm1);
1577 if (takes_ref)
1578 ok(ref2 > ref1, "Test %u: expected ref2 > ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1579 else
1580 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1581 ref3 = get_refcount((IUnknown *)d3drm2);
1582 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1583 ref4 = get_refcount((IUnknown *)d3drm3);
1584 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1585 IUnknown_Release(unknown);
1586 ref2 = get_refcount((IUnknown *)d3drm1);
1587 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1588 ref3 = get_refcount((IUnknown *)d3drm2);
1589 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1590 ref4 = get_refcount((IUnknown *)d3drm3);
1591 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1595 IDirect3DRM_Release(d3drm1);
1596 IDirect3DRM2_Release(d3drm2);
1597 IDirect3DRM3_Release(d3drm3);
1600 static void test_Viewport(void)
1602 IDirectDrawClipper *clipper;
1603 HRESULT hr;
1604 IDirect3DRM *d3drm1;
1605 IDirect3DRM2 *d3drm2;
1606 IDirect3DRM3 *d3drm3;
1607 IDirect3DRMDevice *device1, *d3drm_device1;
1608 IDirect3DRMDevice3 *device3, *d3drm_device3;
1609 IDirect3DRMFrame *frame;
1610 IDirect3DRMFrame3 *frame3;
1611 IDirect3DRMViewport *viewport;
1612 IDirect3DRMViewport2 *viewport2;
1613 IDirect3DViewport *d3d_viewport;
1614 D3DVIEWPORT vp;
1615 D3DVALUE expected_val;
1616 IDirect3DRMObject *obj, *obj2;
1617 GUID driver;
1618 HWND window;
1619 RECT rc;
1620 DWORD data, ref1, ref2, ref3, ref4;
1621 DWORD initial_ref1, initial_ref2, initial_ref3, device_ref, frame_ref, frame_ref2, viewport_ref;
1623 window = create_window();
1624 GetClientRect(window, &rc);
1626 hr = Direct3DRMCreate(&d3drm1);
1627 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1628 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1629 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
1630 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1631 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
1632 initial_ref1 = get_refcount((IUnknown *)d3drm1);
1633 initial_ref2 = get_refcount((IUnknown *)d3drm2);
1634 initial_ref3 = get_refcount((IUnknown *)d3drm3);
1636 hr = DirectDrawCreateClipper(0, &clipper, NULL);
1637 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1639 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
1640 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1642 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1643 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
1644 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1645 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice, (void **)&device1);
1646 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
1648 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame);
1649 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1650 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
1651 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %x).\n", hr);
1653 ref1 = get_refcount((IUnknown *)d3drm1);
1654 ref2 = get_refcount((IUnknown *)d3drm2);
1655 ref3 = get_refcount((IUnknown *)d3drm3);
1656 device_ref = get_refcount((IUnknown *)device1);
1657 frame_ref = get_refcount((IUnknown *)frame);
1659 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, 0, 0, 0, 0, &viewport);
1660 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1661 ref4 = get_refcount((IUnknown *)d3drm1);
1662 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1663 ref4 = get_refcount((IUnknown *)d3drm2);
1664 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1665 ref4 = get_refcount((IUnknown *)d3drm3);
1666 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1667 ref4 = get_refcount((IUnknown *)device1);
1668 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1669 ref4 = get_refcount((IUnknown *)frame);
1670 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1672 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1673 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1674 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device1, d3drm_device1);
1675 IDirect3DRMDevice_Release(d3drm_device1);
1677 IDirect3DRMViewport_Release(viewport);
1678 ref4 = get_refcount((IUnknown *)d3drm1);
1679 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1680 ref4 = get_refcount((IUnknown *)d3drm2);
1681 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1682 ref4 = get_refcount((IUnknown *)d3drm3);
1683 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1684 ref4 = get_refcount((IUnknown *)device1);
1685 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1686 ref4 = get_refcount((IUnknown *)frame);
1687 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1689 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, 0, 0, 0, 0, &viewport);
1690 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1691 ref4 = get_refcount((IUnknown *)d3drm1);
1692 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1693 ref4 = get_refcount((IUnknown *)d3drm2);
1694 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1695 ref4 = get_refcount((IUnknown *)d3drm3);
1696 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1697 ref4 = get_refcount((IUnknown *)device1);
1698 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1699 ref4 = get_refcount((IUnknown *)frame);
1700 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1702 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1703 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1704 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device1, d3drm_device1);
1705 IDirect3DRMDevice_Release(d3drm_device1);
1707 IDirect3DRMViewport_Release(viewport);
1708 ref4 = get_refcount((IUnknown *)d3drm1);
1709 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1710 ref4 = get_refcount((IUnknown *)d3drm2);
1711 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1712 ref4 = get_refcount((IUnknown *)d3drm3);
1713 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1714 ref4 = get_refcount((IUnknown *)device1);
1715 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1716 ref4 = get_refcount((IUnknown *)frame);
1717 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1719 device_ref = get_refcount((IUnknown *)device3);
1720 frame_ref2 = get_refcount((IUnknown *)frame3);
1722 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, 0, 0, 0, 0, &viewport2);
1723 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
1724 ref4 = get_refcount((IUnknown *)d3drm1);
1725 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1726 ref4 = get_refcount((IUnknown *)d3drm2);
1727 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1728 ref4 = get_refcount((IUnknown *)d3drm3);
1729 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1730 ref4 = get_refcount((IUnknown *)device3);
1731 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1732 ref4 = get_refcount((IUnknown *)frame3);
1733 ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
1735 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
1736 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
1737 ok(device3 == d3drm_device3, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
1738 IDirect3DRMDevice3_Release(d3drm_device3);
1740 IDirect3DRMViewport2_Release(viewport2);
1741 ref4 = get_refcount((IUnknown *)d3drm1);
1742 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1743 ref4 = get_refcount((IUnknown *)d3drm2);
1744 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1745 ref4 = get_refcount((IUnknown *)d3drm3);
1746 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1747 ref4 = get_refcount((IUnknown *)device3);
1748 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1749 ref4 = get_refcount((IUnknown *)frame3);
1750 ok(ref4 == frame_ref2, "Expected ref4 == frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
1752 /* Test all failures together */
1753 hr = IDirect3DRM_CreateViewport(d3drm1, NULL, frame, 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, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1756 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1757 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &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 + 1, rc.bottom, &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 + 1, &viewport);
1762 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1763 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom, NULL);
1764 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1766 hr = IDirect3DRM2_CreateViewport(d3drm2, NULL, frame, 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, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1769 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1770 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &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 + 1, rc.bottom, &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 + 1, &viewport);
1775 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1776 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom, NULL);
1777 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1779 hr = IDirect3DRM3_CreateViewport(d3drm3, NULL, frame3, 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, NULL, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1782 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1783 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right + 1, rc.bottom + 1, &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 + 1, rc.bottom, &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 + 1, &viewport2);
1788 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1789 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom, NULL);
1790 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1792 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1793 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
1794 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1795 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1796 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1797 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1798 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1799 ref4 = get_refcount((IUnknown *)d3d_viewport);
1800 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1801 IDirect3DViewport_Release(d3d_viewport);
1802 ref4 = get_refcount((IUnknown *)d3d_viewport);
1803 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1804 IDirect3DViewport_Release(d3d_viewport);
1806 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1807 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1808 vp.dwSize = sizeof(vp);
1809 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1810 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1811 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1812 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1813 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1814 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1815 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1816 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1817 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1818 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1819 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1820 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1821 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1822 IDirect3DViewport_Release(d3d_viewport);
1823 IDirect3DRMViewport_Release(viewport);
1825 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, frame3, rc.left, rc.top, rc.right, rc.bottom, &viewport2);
1826 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
1827 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1828 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1829 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1830 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1831 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1832 ref4 = get_refcount((IUnknown *)d3d_viewport);
1833 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1834 IDirect3DViewport_Release(d3d_viewport);
1835 ref4 = get_refcount((IUnknown *)d3d_viewport);
1836 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1837 IDirect3DViewport_Release(d3d_viewport);
1839 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
1840 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1841 vp.dwSize = sizeof(vp);
1842 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1843 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1844 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1845 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1846 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1847 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1848 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1849 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1850 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1851 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1852 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1853 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1854 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1855 IDirect3DViewport_Release(d3d_viewport);
1856 IDirect3DRMViewport2_Release(viewport2);
1858 hr = IDirect3DRM_CreateViewport(d3drm1, device1, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1859 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %x)\n", hr);
1860 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1861 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1862 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1863 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1864 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1865 ref4 = get_refcount((IUnknown *)d3d_viewport);
1866 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1867 IDirect3DViewport_Release(d3d_viewport);
1868 ref4 = get_refcount((IUnknown *)d3d_viewport);
1869 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1870 IDirect3DViewport_Release(d3d_viewport);
1872 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1873 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1874 vp.dwSize = sizeof(vp);
1875 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1876 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1877 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1878 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
1879 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
1880 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
1881 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
1882 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
1883 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
1884 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
1885 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
1886 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
1887 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
1888 IDirect3DViewport_Release(d3d_viewport);
1890 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMObject, (void**)&obj);
1891 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1892 ok((IDirect3DRMObject*)viewport == obj, "got object pointer %p, expected %p\n", obj, viewport);
1894 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1895 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1897 hr = IDirect3DRMViewport2_QueryInterface(viewport2, &IID_IDirect3DRMObject, (void**)&obj2);
1898 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1899 ok(obj == obj2, "got object pointer %p, expected %p\n", obj2, obj);
1900 ok((IUnknown*)viewport != (IUnknown*)viewport2, "got viewport1 %p, viewport2 %p\n", viewport, viewport2);
1902 IDirect3DRMViewport2_Release(viewport2);
1903 IDirect3DRMObject_Release(obj);
1904 IDirect3DRMObject_Release(obj2);
1906 test_class_name((IDirect3DRMObject *)viewport, "Viewport");
1907 test_object_name((IDirect3DRMObject *)viewport);
1909 /* AppData */
1910 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1911 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1913 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1914 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1916 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1917 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1919 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1920 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1922 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1923 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1925 data = IDirect3DRMViewport2_GetAppData(viewport2);
1926 ok(data == 1, "got %x\n", data);
1927 IDirect3DRMViewport2_Release(viewport2);
1928 IDirect3DRMViewport_Release(viewport);
1930 /* IDirect3DRMViewport*::Init tests */
1931 ref1 = get_refcount((IUnknown *)d3drm1);
1932 ref2 = get_refcount((IUnknown *)d3drm2);
1933 ref3 = get_refcount((IUnknown *)d3drm3);
1934 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMViewport, NULL, &IID_IDirect3DRMViewport,
1935 (void **)&viewport);
1936 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x).\n", hr);
1937 ref4 = get_refcount((IUnknown *)d3drm1);
1938 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1939 ref4 = get_refcount((IUnknown *)d3drm2);
1940 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1941 ref4 = get_refcount((IUnknown *)d3drm3);
1942 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1944 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1945 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1946 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1947 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1949 /* Test all failures together */
1950 hr = IDirect3DRMViewport_Init(viewport, NULL, frame, 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, NULL, rc.left, rc.top, rc.right, rc.bottom);
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 + 1);
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 + 1, rc.bottom);
1957 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1958 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom + 1);
1959 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1961 device_ref = get_refcount((IUnknown *)device1);
1962 frame_ref = get_refcount((IUnknown *)frame);
1963 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom);
1964 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMViewport interface (hr = %#x).\n", hr);
1965 ref4 = get_refcount((IUnknown *)d3drm1);
1966 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1967 ref4 = get_refcount((IUnknown *)d3drm2);
1968 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
1969 ref4 = get_refcount((IUnknown *)d3drm3);
1970 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
1971 ref4 = get_refcount((IUnknown *)device1);
1972 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
1973 ref4 = get_refcount((IUnknown *)frame);
1974 ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
1976 hr = IDirect3DRMViewport_GetDevice(viewport, &d3drm_device1);
1977 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
1978 ok(device1 == d3drm_device1, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
1979 IDirect3DRMDevice_Release(d3drm_device1);
1981 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1982 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1983 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
1984 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1985 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1986 ref4 = get_refcount((IUnknown *)d3d_viewport);
1987 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1988 IDirect3DViewport_Release(d3d_viewport);
1989 ref4 = get_refcount((IUnknown *)d3d_viewport);
1990 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
1991 IDirect3DViewport_Release(d3d_viewport);
1993 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport, &d3d_viewport);
1994 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
1995 vp.dwSize = sizeof(vp);
1996 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
1997 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
1998 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
1999 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
2000 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
2001 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
2002 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
2003 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
2004 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
2005 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
2006 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
2007 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
2008 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
2009 IDirect3DViewport_Release(d3d_viewport);
2011 hr = IDirect3DRMViewport_Init(viewport, device1, frame, rc.left, rc.top, rc.right, rc.bottom);
2012 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2014 IDirect3DRMViewport_Release(viewport);
2015 ref4 = get_refcount((IUnknown *)d3drm1);
2016 todo_wine ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2017 ref4 = get_refcount((IUnknown *)d3drm2);
2018 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2019 ref4 = get_refcount((IUnknown *)d3drm3);
2020 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2021 ref4 = get_refcount((IUnknown *)device1);
2022 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2023 ref4 = get_refcount((IUnknown *)frame);
2024 todo_wine ok(ref4 > frame_ref, "Expected ref4 > frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
2026 ref1 = get_refcount((IUnknown *)d3drm1);
2027 ref2 = get_refcount((IUnknown *)d3drm2);
2028 ref3 = get_refcount((IUnknown *)d3drm3);
2029 hr = IDirect3DRM3_CreateObject(d3drm2, &CLSID_CDirect3DRMViewport, NULL, &IID_IDirect3DRMViewport2,
2030 (void **)&viewport2);
2031 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x).\n", hr);
2032 ref4 = get_refcount((IUnknown *)d3drm1);
2033 ok(ref4 == ref1, "Expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2034 ref4 = get_refcount((IUnknown *)d3drm2);
2035 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2036 ref4 = get_refcount((IUnknown *)d3drm3);
2037 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2039 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2040 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2041 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
2042 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2044 hr = IDirect3DRMViewport2_Init(viewport2, NULL, frame3, 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, NULL, rc.left, rc.top, rc.right, rc.bottom);
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 + 1);
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 + 1, rc.bottom);
2051 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2052 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom + 1);
2053 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2055 device_ref = get_refcount((IUnknown *)device3);
2056 frame_ref2 = get_refcount((IUnknown *)frame3);
2057 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom);
2058 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMViewport2 interface (hr = %#x).\n", hr);
2059 ref4 = get_refcount((IUnknown *)device3);
2060 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2061 ref4 = get_refcount((IUnknown *)frame3);
2062 ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2064 hr = IDirect3DRMViewport2_GetDevice(viewport2, &d3drm_device3);
2065 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
2066 ok(device3 == d3drm_device3, "Expected device returned = %p, got %p.\n", device3, d3drm_device3);
2067 IDirect3DRMDevice3_Release(d3drm_device3);
2069 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2070 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2071 viewport_ref = get_refcount((IUnknown *)d3d_viewport);
2072 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2073 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2074 ref4 = get_refcount((IUnknown *)d3d_viewport);
2075 ok(ref4 > viewport_ref, "Expected ref4 > viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2076 IDirect3DViewport_Release(d3d_viewport);
2077 ref4 = get_refcount((IUnknown *)d3d_viewport);
2078 ok(ref4 == viewport_ref, "Expected ref4 == viewport_ref, got ref4 = %u, viewport_ref = %u.\n", ref4, viewport_ref);
2079 IDirect3DViewport_Release(d3d_viewport);
2081 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
2082 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
2083 vp.dwSize = sizeof(vp);
2084 hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp);
2085 ok(SUCCEEDED(hr), "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr);
2086 ok(vp.dwWidth == rc.right, "Expected viewport width = %u, got %u.\n", rc.right, vp.dwWidth);
2087 ok(vp.dwHeight == rc.bottom, "Expected viewport height = %u, got %u.\n", rc.bottom, vp.dwHeight);
2088 ok(vp.dwX == rc.left, "Expected viewport X position = %u, got %u.\n", rc.left, vp.dwX);
2089 ok(vp.dwY == rc.top, "Expected viewport Y position = %u, got %u.\n", rc.top, vp.dwY);
2090 expected_val = (rc.right > rc.bottom) ? (rc.right / 2.0f) : (rc.bottom / 2.0f);
2091 ok(vp.dvScaleX == expected_val, "Expected dvScaleX = %f, got %f.\n", expected_val, vp.dvScaleX);
2092 ok(vp.dvScaleY == expected_val, "Expected dvScaleY = %f, got %f.\n", expected_val, vp.dvScaleY);
2093 expected_val = vp.dwWidth / (2.0f * vp.dvScaleX);
2094 ok(vp.dvMaxX == expected_val, "Expected dvMaxX = %f, got %f.\n", expected_val, vp.dvMaxX);
2095 expected_val = vp.dwHeight / (2.0f * vp.dvScaleY);
2096 ok(vp.dvMaxY == expected_val, "Expected dvMaxY = %f, got %f.\n", expected_val, vp.dvMaxY);
2097 IDirect3DViewport_Release(d3d_viewport);
2099 hr = IDirect3DRMViewport2_Init(viewport2, device3, frame3, rc.left, rc.top, rc.right, rc.bottom);
2100 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2102 IDirect3DRMViewport2_Release(viewport2);
2103 ref4 = get_refcount((IUnknown *)d3drm1);
2104 todo_wine ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2105 ref4 = get_refcount((IUnknown *)d3drm2);
2106 ok(ref4 == ref2, "Expected ref4 == ref2, got ref2 = %u, ref4 = %u.\n", ref2, ref4);
2107 ref4 = get_refcount((IUnknown *)d3drm3);
2108 ok(ref4 == ref3, "Expected ref4 == ref3, got ref3 = %u, ref4 = %u.\n", ref3, ref4);
2109 ref4 = get_refcount((IUnknown *)device3);
2110 ok(ref4 == device_ref, "Expected ref4 == device_ref, got device_ref = %u, ref4 = %u.\n", device_ref, ref4);
2111 ref4 = get_refcount((IUnknown *)frame3);
2112 todo_wine ok(ref4 > frame_ref2, "Expected ref4 > frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2114 IDirect3DRMDevice3_Release(device3);
2115 IDirect3DRMDevice_Release(device1);
2116 ref4 = get_refcount((IUnknown *)d3drm1);
2117 ok(ref4 > initial_ref1, "Expected ref4 > initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2118 ref4 = get_refcount((IUnknown *)d3drm2);
2119 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2120 ref4 = get_refcount((IUnknown *)d3drm3);
2121 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2122 ref4 = get_refcount((IUnknown *)frame);
2123 ok(ref4 == frame_ref, "Expected ref4 == frame_ref, got frame_ref = %u, ref4 = %u.\n", frame_ref, ref4);
2124 ref4 = get_refcount((IUnknown *)frame3);
2125 ok(ref4 == frame_ref2, "Expected ref4 == frame_ref2, got frame_ref2 = %u, ref4 = %u.\n", frame_ref2, ref4);
2127 IDirect3DRMFrame3_Release(frame3);
2128 ref4 = get_refcount((IUnknown *)d3drm1);
2129 ok(ref4 > initial_ref1, "Expected ref4 > initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2130 ref4 = get_refcount((IUnknown *)d3drm2);
2131 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2132 ref4 = get_refcount((IUnknown *)d3drm3);
2133 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2135 IDirect3DRMFrame_Release(frame);
2136 ref4 = get_refcount((IUnknown *)d3drm1);
2137 ok(ref4 == initial_ref1, "Expected ref4 == initial_ref1, got initial_ref1 = %u, ref4 = %u.\n", initial_ref1, ref4);
2138 ref4 = get_refcount((IUnknown *)d3drm2);
2139 ok(ref4 == initial_ref2, "Expected ref4 == initial_ref2, got initial_ref2 = %u, ref4 = %u.\n", initial_ref2, ref4);
2140 ref4 = get_refcount((IUnknown *)d3drm3);
2141 ok(ref4 == initial_ref3, "Expected ref4 == initial_ref3, got initial_ref3 = %u, ref4 = %u.\n", initial_ref3, ref4);
2142 IDirectDrawClipper_Release(clipper);
2144 IDirect3DRM3_Release(d3drm3);
2145 IDirect3DRM2_Release(d3drm2);
2146 IDirect3DRM_Release(d3drm1);
2147 DestroyWindow(window);
2150 static void test_Light(void)
2152 IDirect3DRMObject *object;
2153 HRESULT hr;
2154 IDirect3DRM *d3drm;
2155 IDirect3DRMLight *light;
2156 D3DRMLIGHTTYPE type;
2157 D3DCOLOR color;
2159 hr = Direct3DRMCreate(&d3drm);
2160 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2162 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.5, 0.5, 0.5, &light);
2163 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
2165 hr = IDirect3DRMLight_QueryInterface(light, &IID_IDirect3DRMObject, (void **)&object);
2166 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMObject, hr %#x.\n", hr);
2167 IDirect3DRMObject_Release(object);
2169 test_class_name((IDirect3DRMObject *)light, "Light");
2170 test_object_name((IDirect3DRMObject *)light);
2172 type = IDirect3DRMLight_GetType(light);
2173 ok(type == D3DRMLIGHT_SPOT, "wrong type (%u)\n", type);
2175 color = IDirect3DRMLight_GetColor(light);
2176 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
2178 hr = IDirect3DRMLight_SetType(light, D3DRMLIGHT_POINT);
2179 ok(hr == D3DRM_OK, "Cannot set type (hr = %x)\n", hr);
2180 type = IDirect3DRMLight_GetType(light);
2181 ok(type == D3DRMLIGHT_POINT, "wrong type (%u)\n", type);
2183 hr = IDirect3DRMLight_SetColor(light, 0xff180587);
2184 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
2185 color = IDirect3DRMLight_GetColor(light);
2186 ok(color == 0xff180587, "wrong color (%x)\n", color);
2188 hr = IDirect3DRMLight_SetColorRGB(light, 0.5, 0.5, 0.5);
2189 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
2190 color = IDirect3DRMLight_GetColor(light);
2191 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
2193 IDirect3DRMLight_Release(light);
2195 IDirect3DRM_Release(d3drm);
2198 static void test_Material2(void)
2200 HRESULT hr;
2201 IDirect3DRM *d3drm;
2202 IDirect3DRM3 *d3drm3;
2203 IDirect3DRMMaterial2 *material2;
2204 D3DVALUE r, g, b;
2206 hr = Direct3DRMCreate(&d3drm);
2207 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2209 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
2211 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
2212 IDirect3DRM_Release(d3drm);
2213 return;
2216 hr = IDirect3DRM3_CreateMaterial(d3drm3, 18.5f, &material2);
2217 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMaterial2 interface (hr = %x)\n", hr);
2219 test_class_name((IDirect3DRMObject *)material2, "Material");
2220 test_object_name((IDirect3DRMObject *)material2);
2222 r = IDirect3DRMMaterial2_GetPower(material2);
2223 ok(r == 18.5f, "wrong power (%f)\n", r);
2225 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
2226 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2227 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);
2229 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
2230 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2231 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);
2233 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
2234 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2235 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);
2237 hr = IDirect3DRMMaterial2_SetPower(material2, 5.87f);
2238 ok(hr == D3DRM_OK, "Cannot set power (hr = %x)\n", hr);
2239 r = IDirect3DRMMaterial2_GetPower(material2);
2240 ok(r == 5.87f, "wrong power (%f)\n", r);
2242 hr = IDirect3DRMMaterial2_SetEmissive(material2, 0.5f, 0.5f, 0.5f);
2243 ok(hr == D3DRM_OK, "Cannot set emissive (hr = %x)\n", hr);
2244 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
2245 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
2246 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);
2248 hr = IDirect3DRMMaterial2_SetSpecular(material2, 0.6f, 0.6f, 0.6f);
2249 ok(hr == D3DRM_OK, "Cannot set specular (hr = %x)\n", hr);
2250 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
2251 ok(hr == D3DRM_OK, "Cannot get specular (hr = %x)\n", hr);
2252 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);
2254 hr = IDirect3DRMMaterial2_SetAmbient(material2, 0.7f, 0.7f, 0.7f);
2255 ok(hr == D3DRM_OK, "Cannot set ambient (hr = %x)\n", hr);
2256 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
2257 ok(hr == D3DRM_OK, "Cannot get ambient (hr = %x)\n", hr);
2258 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);
2260 IDirect3DRMMaterial2_Release(material2);
2262 IDirect3DRM3_Release(d3drm3);
2263 IDirect3DRM_Release(d3drm);
2266 static void test_Texture(void)
2268 HRESULT hr;
2269 IDirect3DRM *d3drm1;
2270 IDirect3DRM2 *d3drm2;
2271 IDirect3DRM3 *d3drm3;
2272 IDirect3DRMTexture *texture1;
2273 IDirect3DRMTexture2 *texture2;
2274 IDirect3DRMTexture3 *texture3;
2275 IDirectDrawSurface *surface;
2277 D3DRMIMAGE initimg =
2279 2, 2, 1, 1, 32,
2280 TRUE, 2 * sizeof(DWORD), NULL, NULL,
2281 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
2283 testimg =
2285 0, 0, 0, 0, 0,
2286 TRUE, 0, (void *)0xcafebabe, NULL,
2287 0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
2289 *d3drm_img = NULL;
2291 DWORD pixel[4] = { 20000, 30000, 10000, 0 };
2292 ULONG ref1, ref2, ref3, ref4;
2294 hr = Direct3DRMCreate(&d3drm1);
2295 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2296 ref1 = get_refcount((IUnknown *)d3drm1);
2298 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2299 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2301 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2302 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2304 /* Test NULL params */
2305 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
2306 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, &texture1);
2307 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2308 ok(!texture1, "Expected texture returned == NULL, got %p.\n", texture1);
2309 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, NULL);
2310 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2312 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
2313 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, &texture2);
2314 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2315 ok(!texture2, "Expected texture returned == NULL, got %p.\n", texture2);
2316 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, NULL);
2317 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2319 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
2320 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, &texture3);
2321 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2322 ok(!texture3, "Expected texture returned == NULL, got %p.\n", texture3);
2323 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, NULL);
2324 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2326 /* Tests for validation of D3DRMIMAGE struct */
2327 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
2328 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2329 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
2330 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2331 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
2332 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2333 IDirect3DRMTexture_Release(texture1);
2334 IDirect3DRMTexture2_Release(texture2);
2335 IDirect3DRMTexture3_Release(texture3);
2337 testimg.rgb = 0;
2338 testimg.palette = (void *)0xdeadbeef;
2339 testimg.palette_size = 0x39;
2340 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
2341 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2342 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
2343 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2344 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
2345 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2346 IDirect3DRMTexture_Release(texture1);
2347 IDirect3DRMTexture2_Release(texture2);
2348 IDirect3DRMTexture3_Release(texture3);
2350 initimg.rgb = 0;
2351 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
2352 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2353 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2354 ok(!texture1, "Expected texture == NULL, got %p.\n", texture1);
2355 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
2356 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2357 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2358 ok(!texture2, "Expected texture == NULL, got %p.\n", texture2);
2359 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
2360 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2361 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2362 ok(!texture3, "Expected texture == NULL, got %p.\n", texture3);
2363 initimg.rgb = 1;
2364 initimg.red_mask = 0;
2365 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2366 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2367 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2368 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2369 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2370 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2371 initimg.red_mask = 0x000000ff;
2372 initimg.green_mask = 0;
2373 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2374 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2375 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2376 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2377 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2378 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2379 initimg.green_mask = 0x0000ff00;
2380 initimg.blue_mask = 0;
2381 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2382 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2383 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2384 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2385 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2386 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2387 initimg.blue_mask = 0x00ff0000;
2388 initimg.buffer1 = NULL;
2389 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2390 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2391 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2392 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2393 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2394 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
2396 initimg.buffer1 = &pixel;
2397 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
2398 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
2399 ref2 = get_refcount((IUnknown *)d3drm1);
2400 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2401 ref3 = get_refcount((IUnknown *)d3drm2);
2402 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2403 ref4 = get_refcount((IUnknown *)d3drm3);
2404 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2405 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
2406 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2407 ref2 = get_refcount((IUnknown *)d3drm1);
2408 ok(ref2 > ref1 + 1, "expected ref2 > (ref1 + 1), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2409 ref3 = get_refcount((IUnknown *)d3drm2);
2410 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2411 ref4 = get_refcount((IUnknown *)d3drm3);
2412 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2413 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
2414 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2415 ref2 = get_refcount((IUnknown *)d3drm1);
2416 ok(ref2 > ref1 + 2, "expected ref2 > (ref1 + 2), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2417 ref3 = get_refcount((IUnknown *)d3drm2);
2418 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2419 ref4 = get_refcount((IUnknown *)d3drm3);
2420 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2422 /* Created from image, GetSurface() does not work. */
2423 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, NULL);
2424 ok(hr == D3DRMERR_BADVALUE, "GetSurface() expected to fail, %#x\n", hr);
2426 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &surface);
2427 ok(hr == D3DRMERR_NOTCREATEDFROMDDS, "GetSurface() expected to fail, %#x\n", hr);
2429 /* Test all failures together */
2430 test_class_name((IDirect3DRMObject *)texture1, "Texture");
2431 test_class_name((IDirect3DRMObject *)texture2, "Texture");
2432 test_class_name((IDirect3DRMObject *)texture3, "Texture");
2433 test_object_name((IDirect3DRMObject *)texture1);
2434 test_object_name((IDirect3DRMObject *)texture2);
2435 test_object_name((IDirect3DRMObject *)texture3);
2437 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
2438 ok(!!d3drm_img, "Failed to get image.\n");
2439 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2441 IDirect3DRMTexture_Release(texture1);
2442 ref2 = get_refcount((IUnknown *)d3drm1);
2443 ok(ref2 - 2 == ref1, "expected (ref2 - 2) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2444 ref3 = get_refcount((IUnknown *)d3drm2);
2445 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2446 ref4 = get_refcount((IUnknown *)d3drm3);
2447 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2449 d3drm_img = NULL;
2450 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
2451 ok(!!d3drm_img, "Failed to get image.\n");
2452 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2454 IDirect3DRMTexture2_Release(texture2);
2455 ref2 = get_refcount((IUnknown *)d3drm1);
2456 ok(ref2 - 1 == ref1, "expected (ref2 - 1) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2457 ref3 = get_refcount((IUnknown *)d3drm2);
2458 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2459 ref4 = get_refcount((IUnknown *)d3drm3);
2460 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2462 d3drm_img = NULL;
2463 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
2464 ok(!!d3drm_img, "Failed to get image.\n");
2465 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2467 IDirect3DRMTexture3_Release(texture3);
2468 ref2 = get_refcount((IUnknown *)d3drm1);
2469 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2470 ref3 = get_refcount((IUnknown *)d3drm2);
2471 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2472 ref4 = get_refcount((IUnknown *)d3drm3);
2473 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2475 /* InitFromImage tests */
2476 /* Tests for validation of D3DRMIMAGE struct */
2477 testimg.rgb = 1;
2478 testimg.palette = NULL;
2479 testimg.palette_size = 0;
2480 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2481 (void **)&texture2);
2482 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2483 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2484 (void **)&texture3);
2485 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2486 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
2487 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2488 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
2489 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2490 IDirect3DRMTexture2_Release(texture2);
2491 IDirect3DRMTexture3_Release(texture3);
2493 testimg.rgb = 0;
2494 testimg.palette = (void *)0xdeadbeef;
2495 testimg.palette_size = 0x39;
2496 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2497 (void **)&texture2);
2498 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2499 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2500 (void **)&texture3);
2501 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2502 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
2503 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
2504 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
2505 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
2506 IDirect3DRMTexture2_Release(texture2);
2507 IDirect3DRMTexture3_Release(texture3);
2509 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
2510 (void **)&texture2);
2511 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
2512 ref2 = get_refcount((IUnknown *)texture2);
2513 hr = IDirect3DRMTexture2_InitFromImage(texture2, NULL);
2514 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2515 ref3 = get_refcount((IUnknown *)texture2);
2516 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2518 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2519 (void **)&texture3);
2520 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2521 ref2 = get_refcount((IUnknown *)texture3);
2522 hr = IDirect3DRMTexture3_InitFromImage(texture3, NULL);
2523 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2524 ref3 = get_refcount((IUnknown *)texture3);
2525 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2527 initimg.rgb = 0;
2528 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2529 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2530 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2531 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2532 initimg.rgb = 1;
2533 initimg.red_mask = 0;
2534 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2535 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2536 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2537 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2538 initimg.red_mask = 0x000000ff;
2539 initimg.green_mask = 0;
2540 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2541 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2542 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2543 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2544 initimg.green_mask = 0x0000ff00;
2545 initimg.blue_mask = 0;
2546 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2547 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2548 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2549 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2550 initimg.blue_mask = 0x00ff0000;
2551 initimg.buffer1 = NULL;
2552 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2553 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2554 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2555 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2556 initimg.buffer1 = &pixel;
2558 d3drm_img = NULL;
2559 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2560 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 from image (hr = %#x).\n", hr);
2561 ref2 = get_refcount((IUnknown *)d3drm1);
2562 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2563 ref3 = get_refcount((IUnknown *)d3drm2);
2564 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2565 ref4 = get_refcount((IUnknown *)d3drm3);
2566 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2568 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2569 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2570 /* Release leaked reference to d3drm1 */
2571 IDirect3DRM_Release(d3drm1);
2573 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
2574 ok(!!d3drm_img, "Failed to get image.\n");
2575 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2576 IDirect3DRMTexture2_Release(texture2);
2577 ref2 = get_refcount((IUnknown *)d3drm1);
2578 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2579 ref3 = get_refcount((IUnknown *)d3drm2);
2580 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2581 ref4 = get_refcount((IUnknown *)d3drm3);
2582 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2584 d3drm_img = NULL;
2585 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2586 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 from image (hr = %#x).\n", hr);
2587 ref2 = get_refcount((IUnknown *)d3drm1);
2588 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2589 ref3 = get_refcount((IUnknown *)d3drm2);
2590 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2591 ref4 = get_refcount((IUnknown *)d3drm3);
2592 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2594 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2595 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2596 IDirect3DRM_Release(d3drm1);
2598 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
2599 ok(!!d3drm_img, "Failed to get image.\n");
2600 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2601 IDirect3DRMTexture3_Release(texture3);
2602 ref2 = get_refcount((IUnknown *)d3drm1);
2603 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2604 ref3 = get_refcount((IUnknown *)d3drm2);
2605 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2606 ref4 = get_refcount((IUnknown *)d3drm3);
2607 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2609 IDirect3DRM3_Release(d3drm3);
2610 IDirect3DRM2_Release(d3drm2);
2611 IDirect3DRM_Release(d3drm1);
2614 static void test_Device(void)
2616 IDirectDrawClipper *pClipper;
2617 HRESULT hr;
2618 IDirect3DRM *d3drm;
2619 IDirect3DRMDevice *device;
2620 IDirect3DRMWinDevice *win_device;
2621 GUID driver;
2622 HWND window;
2623 RECT rc;
2625 window = create_window();
2626 GetClientRect(window, &rc);
2628 hr = Direct3DRMCreate(&d3drm);
2629 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2631 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
2632 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
2634 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
2635 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
2637 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
2638 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
2639 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
2641 test_class_name((IDirect3DRMObject *)device, "Device");
2642 test_object_name((IDirect3DRMObject *)device);
2644 /* WinDevice */
2645 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMWinDevice, (void **)&win_device)))
2647 win_skip("Cannot get IDirect3DRMWinDevice interface (hr = %x), skipping tests\n", hr);
2648 goto cleanup;
2651 test_class_name((IDirect3DRMObject *)win_device, "Device");
2652 test_object_name((IDirect3DRMObject *)win_device);
2653 IDirect3DRMWinDevice_Release(win_device);
2655 cleanup:
2656 IDirect3DRMDevice_Release(device);
2657 IDirectDrawClipper_Release(pClipper);
2659 IDirect3DRM_Release(d3drm);
2660 DestroyWindow(window);
2663 static void test_frame_transform(void)
2665 HRESULT hr;
2666 IDirect3DRM *d3drm;
2667 IDirect3DRMFrame *frame;
2668 D3DRMMATRIX4D matrix;
2670 hr = Direct3DRMCreate(&d3drm);
2671 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2673 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
2674 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
2676 hr = IDirect3DRMFrame_GetTransform(frame, matrix);
2677 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetTransform returned hr = %x\n", hr);
2678 ok(!memcmp(matrix, identity, sizeof(D3DRMMATRIX4D)), "Returned matrix is not identity\n");
2680 IDirect3DRMFrame_Release(frame);
2681 IDirect3DRM_Release(d3drm);
2684 static int nb_objects = 0;
2685 static const GUID* refiids[] =
2687 &IID_IDirect3DRMMeshBuilder,
2688 &IID_IDirect3DRMMeshBuilder,
2689 &IID_IDirect3DRMFrame,
2690 &IID_IDirect3DRMMaterial /* Not taken into account and not notified */
2693 static void __cdecl object_load_callback(IDirect3DRMObject *object, REFIID objectguid, void *arg)
2695 ok(object != NULL, "Arg 1 should not be null\n");
2696 ok(IsEqualGUID(objectguid, refiids[nb_objects]), "Arg 2 is incorrect\n");
2697 ok(arg == (void *)0xdeadbeef, "Arg 3 should be 0xdeadbeef (got %p)\n", arg);
2698 nb_objects++;
2701 static void test_d3drm_load(void)
2703 HRESULT hr;
2704 IDirect3DRM *d3drm;
2705 D3DRMLOADMEMORY info;
2706 const GUID* req_refiids[] = { &IID_IDirect3DRMMeshBuilder, &IID_IDirect3DRMFrame, &IID_IDirect3DRMMaterial };
2708 hr = Direct3DRMCreate(&d3drm);
2709 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2711 info.lpMemory = data_d3drm_load;
2712 info.dSize = strlen(data_d3drm_load);
2713 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID **)req_refiids, 3, D3DRMLOAD_FROMMEMORY,
2714 object_load_callback, (void *)0xdeadbeef, NULL, NULL, NULL);
2715 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2716 ok(nb_objects == 3, "Should have loaded 3 objects (got %d)\n", nb_objects);
2718 IDirect3DRM_Release(d3drm);
2721 IDirect3DRMMeshBuilder *mesh_builder = NULL;
2723 static void __cdecl object_load_callback_frame(IDirect3DRMObject *object, REFIID object_guid, void *arg)
2725 HRESULT hr;
2726 IDirect3DRMFrame *frame;
2727 IDirect3DRMVisualArray *array;
2728 IDirect3DRMVisual *visual;
2729 ULONG size;
2730 char name[128];
2732 hr = IDirect3DRMObject_QueryInterface(object, &IID_IDirect3DRMFrame, (void**)&frame);
2733 ok(hr == D3DRM_OK, "IDirect3DRMObject_QueryInterface returned %x\n", hr);
2735 hr = IDirect3DRMFrame_GetVisuals(frame, &array);
2736 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetVisuals returned %x\n", hr);
2738 size = IDirect3DRMVisualArray_GetSize(array);
2739 ok(size == 1, "Wrong size %u returned, expected 1\n", size);
2741 hr = IDirect3DRMVisualArray_GetElement(array, 0, &visual);
2742 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetElement returned %x\n", hr);
2744 hr = IDirect3DRMVisual_QueryInterface(visual, &IID_IDirect3DRMMeshBuilder, (void**)&mesh_builder);
2745 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetSize returned %x\n", hr);
2747 size = sizeof(name);
2748 hr = IDirect3DRMMeshBuilder_GetName(mesh_builder, &size, name);
2749 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned %x\n", hr);
2750 ok(!strcmp(name, "mesh1"), "Wrong name %s, expected mesh1\n", name);
2752 IDirect3DRMVisual_Release(visual);
2753 IDirect3DRMVisualArray_Release(array);
2754 IDirect3DRMFrame_Release(frame);
2757 struct {
2758 int vertex_count;
2759 int face_count;
2760 int vertex_per_face;
2761 int face_data_size;
2762 DWORD color;
2763 float power;
2764 float specular[3];
2765 float emissive[3];
2766 } groups[3] = {
2767 { 4, 3, 3, 9, 0x4c0000ff, 30.0f, { 0.31f, 0.32f, 0.33f }, { 0.34f, 0.35f, 0.36f } },
2768 { 4, 2, 3, 6, 0x3300ff00, 20.0f, { 0.21f, 0.22f, 0.23f }, { 0.24f, 0.25f, 0.26f } },
2769 { 3, 1, 3, 3, 0x19ff0000, 10.0f, { 0.11f, 0.12f, 0.13f }, { 0.14f, 0.15f, 0.16f } }
2772 static void test_frame_mesh_materials(void)
2774 HRESULT hr;
2775 IDirect3DRM *d3drm;
2776 D3DRMLOADMEMORY info;
2777 const GUID *req_refiids[] = { &IID_IDirect3DRMFrame };
2778 IDirect3DRMMesh *mesh;
2779 ULONG size;
2780 IDirect3DRMMaterial *material;
2781 IDirect3DRMTexture *texture;
2782 int i;
2784 hr = Direct3DRMCreate(&d3drm);
2785 ok(hr == D3DRM_OK, "Direct3DRMCreate returned %x\n", hr);
2787 info.lpMemory = data_frame_mesh_materials;
2788 info.dSize = strlen(data_frame_mesh_materials);
2789 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID**)req_refiids, 1, D3DRMLOAD_FROMMEMORY, object_load_callback_frame, (void*)0xdeadbeef, NULL, NULL, NULL);
2790 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2792 hr = IDirect3DRMMeshBuilder_CreateMesh(mesh_builder, &mesh);
2793 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_CreateMesh returned %x\n", hr);
2795 size = IDirect3DRMMesh_GetGroupCount(mesh);
2796 ok(size == 3, "Wrong size %u returned, expected 3\n", size);
2798 for (i = 0; i < size; i++)
2800 D3DVALUE red, green, blue, power;
2801 D3DCOLOR color;
2802 unsigned vertex_count, face_count, vertex_per_face;
2803 DWORD face_data_size;
2805 hr = IDirect3DRMMesh_GetGroup(mesh, i, &vertex_count, &face_count, &vertex_per_face, &face_data_size, NULL);
2806 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroup returned %x\n", i, hr);
2807 ok(vertex_count == groups[i].vertex_count, "Group %d: Wrong vertex count %d, expected %d\n", i, vertex_count, groups[i].vertex_count);
2808 ok(face_count == groups[i].face_count, "Group %d: Wrong face count %d; expected %d\n", i, face_count, groups[i].face_count);
2809 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);
2810 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);
2812 color = IDirect3DRMMesh_GetGroupColor(mesh, i);
2813 ok(color == groups[i].color, "Group %d: Wrong color %x, expected %x\n", i, color, groups[i].color);
2815 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, i, &material);
2816 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupMaterial returned %x\n", i, hr);
2817 ok(material != NULL, "Group %d: No material\n", i);
2818 power = IDirect3DRMMaterial_GetPower(material);
2819 ok(power == groups[i].power, "Group %d: Wrong power %f, expected %f\n", i, power, groups[i].power);
2820 hr = IDirect3DRMMaterial_GetSpecular(material, &red, &green, &blue);
2821 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetSpecular returned %x\n", i, hr);
2822 ok(red == groups[i].specular[0], "Group %d: Wrong specular red %f, expected %f\n", i, red, groups[i].specular[0]);
2823 ok(green == groups[i].specular[1], "Group %d: Wrong specular green %f, pD3DRMexpected %f\n", i, green, groups[i].specular[1]);
2824 ok(blue == groups[i].specular[2], "Group %d: Wrong specular blue %f, expected %f\n", i, blue, groups[i].specular[2]);
2825 hr = IDirect3DRMMaterial_GetEmissive(material, &red, &green, &blue);
2826 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetEmissive returned %x\n", i, hr);
2827 ok(red == groups[i].emissive[0], "Group %d: Wrong emissive red %f, expected %f\n", i, red, groups[i].emissive[0]);
2828 ok(green == groups[i].emissive[1], "Group %d: Wrong emissive green %f, expected %f\n", i, green, groups[i].emissive[1]);
2829 ok(blue == groups[i].emissive[2], "Group %d: Wrong emissive blue %f, expected %f\n", i, blue, groups[i].emissive[2]);
2831 hr = IDirect3DRMMesh_GetGroupTexture(mesh, i, &texture);
2832 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupTexture returned %x\n", i, hr);
2833 ok(!texture, "Group %d: Unexpected texture\n", i);
2835 if (material)
2836 IDirect3DRMMaterial_Release(material);
2837 if (texture)
2838 IDirect3DRMTexture_Release(texture);
2841 IDirect3DRMMesh_Release(mesh);
2842 IDirect3DRMMeshBuilder_Release(mesh_builder);
2843 IDirect3DRM_Release(d3drm);
2846 struct qi_test
2848 REFIID iid;
2849 REFIID refcount_iid;
2850 REFIID vtable_iid;
2851 HRESULT hr;
2854 static void test_qi(const char *test_name, IUnknown *base_iface,
2855 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
2857 ULONG refcount, expected_refcount;
2858 IUnknown *iface1, *iface2;
2859 HRESULT hr;
2860 UINT i, j;
2862 for (i = 0; i < entry_count; ++i)
2864 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
2865 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
2866 if (SUCCEEDED(hr))
2868 for (j = 0; j < entry_count; ++j)
2870 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
2871 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
2872 if (SUCCEEDED(hr))
2874 expected_refcount = 0;
2875 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
2876 ++expected_refcount;
2877 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
2878 ++expected_refcount;
2879 refcount = IUnknown_Release(iface2);
2880 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2881 refcount, test_name, i, j, expected_refcount);
2882 if (tests[i].vtable_iid && tests[j].vtable_iid && IsEqualGUID(tests[i].vtable_iid, tests[j].vtable_iid))
2883 ok(iface1 == iface2,
2884 "Expected iface1 == iface2 for test \"%s\" %u, %u. Got iface1 = %p, iface 2 = %p.\n",
2885 test_name, i, j, iface1, iface2);
2886 else if (tests[i].vtable_iid && tests[j].vtable_iid)
2887 ok(iface1 != iface2,
2888 "Expected iface1 != iface2 for test \"%s\" %u, %u. Got iface1 == iface2 == %p.\n",
2889 test_name, i, j, iface1);
2893 expected_refcount = 0;
2894 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
2895 ++expected_refcount;
2896 refcount = IUnknown_Release(iface1);
2897 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2898 refcount, test_name, i, expected_refcount);
2903 static void test_d3drm_qi(void)
2905 static const struct qi_test tests[] =
2907 { &IID_IDirect3DRM3, &IID_IDirect3DRM3, &IID_IDirect3DRM3, S_OK },
2908 { &IID_IDirect3DRM2, &IID_IDirect3DRM2, &IID_IDirect3DRM2, S_OK },
2909 { &IID_IDirect3DRM, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
2910 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2911 { &IID_IDirect3DRMObject, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2912 { &IID_IDirect3DRMObject2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2913 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2914 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2915 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2916 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2917 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2918 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2919 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2920 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2921 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2922 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2923 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2924 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2925 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2926 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2927 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2928 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2929 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2930 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2931 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2932 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2933 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2934 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2935 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2936 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2937 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2938 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2939 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2940 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2941 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2942 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2943 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2944 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2945 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2946 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2947 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2948 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2949 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2950 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2951 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2952 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2953 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2954 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2955 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2956 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2957 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2958 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2959 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2960 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2961 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2962 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2963 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2964 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2965 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2966 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2967 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2968 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2969 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2970 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2971 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2972 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2973 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2974 { &IID_IUnknown, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
2976 HRESULT hr;
2977 IDirect3DRM *d3drm;
2979 hr = Direct3DRMCreate(&d3drm);
2980 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2982 test_qi("d3drm_qi", (IUnknown *)d3drm, &IID_IDirect3DRM, tests, sizeof(tests) / sizeof(*tests));
2984 IDirect3DRM_Release(d3drm);
2987 static void test_frame_qi(void)
2989 static const struct qi_test tests[] =
2991 { &IID_IDirect3DRMFrame3, &IID_IUnknown, &IID_IDirect3DRMFrame3, S_OK },
2992 { &IID_IDirect3DRMFrame2, &IID_IUnknown, &IID_IDirect3DRMFrame2, S_OK },
2993 { &IID_IDirect3DRMFrame, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
2994 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2995 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2996 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
2997 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2998 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2999 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3000 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3001 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3002 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3003 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
3004 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3005 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3006 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3007 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3008 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3009 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3010 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3011 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3012 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3013 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3014 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3015 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3016 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3017 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3018 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3019 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3020 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3021 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3022 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3023 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3024 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3025 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3026 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3027 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3028 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3029 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3030 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3031 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3032 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3033 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3034 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3035 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3036 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3037 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3038 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3039 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3040 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3041 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3042 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3043 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3044 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3045 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3046 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3047 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3048 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3049 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3050 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3051 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3052 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3053 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3054 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3055 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3056 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3057 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
3059 HRESULT hr;
3060 IDirect3DRM *d3drm1;
3061 IDirect3DRM2 *d3drm2;
3062 IDirect3DRM3 *d3drm3;
3063 IDirect3DRMFrame *frame1;
3064 IDirect3DRMFrame2 *frame2;
3065 IDirect3DRMFrame3 *frame3;
3066 IUnknown *unknown;
3068 hr = Direct3DRMCreate(&d3drm1);
3069 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
3071 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
3072 ok(hr == D3DRM_OK, "Failed to create frame1 (hr = %x)\n", hr);
3073 hr = IDirect3DRMFrame_QueryInterface(frame1, &IID_IUnknown, (void **)&unknown);
3074 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame1 (hr = %x)\n", hr);
3075 IDirect3DRMFrame_Release(frame1);
3076 test_qi("frame1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3077 IUnknown_Release(unknown);
3079 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3080 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3081 hr = IDirect3DRM2_CreateFrame(d3drm2, NULL, &frame2);
3082 ok(hr == D3DRM_OK, "Failed to create frame2 (hr = %x)\n", hr);
3083 hr = IDirect3DRMFrame2_QueryInterface(frame2, &IID_IUnknown, (void **)&unknown);
3084 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame2 (hr = %x)\n", hr);
3085 IDirect3DRMFrame2_Release(frame2);
3086 test_qi("frame2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3087 IUnknown_Release(unknown);
3089 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3090 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3091 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
3092 ok(hr == D3DRM_OK, "Failed to create frame3 (hr = %x)\n", hr);
3093 hr = IDirect3DRMFrame3_QueryInterface(frame3, &IID_IUnknown, (void **)&unknown);
3094 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame3 (hr = %x)\n", hr);
3095 IDirect3DRMFrame3_Release(frame3);
3096 test_qi("frame3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3097 IUnknown_Release(unknown);
3099 IDirect3DRM3_Release(d3drm3);
3100 IDirect3DRM2_Release(d3drm2);
3101 IDirect3DRM_Release(d3drm1);
3104 static void test_device_qi(void)
3106 static const struct qi_test tests[] =
3108 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3109 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3110 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3111 { &IID_IDirect3DRMDevice, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
3112 { &IID_IDirect3DRMDevice2, &IID_IUnknown, &IID_IDirect3DRMDevice2, S_OK, },
3113 { &IID_IDirect3DRMDevice3, &IID_IUnknown, &IID_IDirect3DRMDevice3, S_OK, },
3114 { &IID_IDirect3DRMWinDevice, &IID_IUnknown, &IID_IDirect3DRMWinDevice, S_OK, },
3115 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
3116 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3117 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3118 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3119 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3120 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3121 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3122 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3123 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3124 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3125 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3126 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3127 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3128 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3129 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3130 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3131 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3132 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3133 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3134 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3135 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3136 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3137 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3138 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3139 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3140 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3141 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3142 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3143 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3144 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3145 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3146 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3147 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3148 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3149 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3150 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3151 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3152 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3153 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3154 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3155 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3156 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3157 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3158 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3159 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3160 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3161 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3162 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3163 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3164 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3165 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3166 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3167 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3168 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3169 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3170 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3171 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3172 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3173 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3174 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
3175 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
3177 HRESULT hr;
3178 IDirect3DRM *d3drm1;
3179 IDirect3DRM2 *d3drm2;
3180 IDirect3DRM3 *d3drm3;
3181 IDirectDrawClipper *clipper;
3182 IDirect3DRMDevice *device1;
3183 IDirect3DRMDevice2 *device2;
3184 IDirect3DRMDevice3 *device3;
3185 IUnknown *unknown;
3186 HWND window;
3187 GUID driver;
3188 RECT rc;
3190 window = create_window();
3191 GetClientRect(window, &rc);
3192 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3193 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
3194 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3195 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
3197 hr = Direct3DRMCreate(&d3drm1);
3198 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
3199 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
3200 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
3201 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
3202 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IUnknown, (void **)&unknown);
3203 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice (hr = %x)\n", hr);
3204 IDirect3DRMDevice_Release(device1);
3205 test_qi("device1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3206 IUnknown_Release(unknown);
3208 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3209 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3210 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
3211 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %x)\n", hr);
3212 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IUnknown, (void **)&unknown);
3213 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice2 (hr = %x)\n", hr);
3214 IDirect3DRMDevice2_Release(device2);
3215 test_qi("device2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3216 IUnknown_Release(unknown);
3218 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3219 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3220 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
3221 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
3222 IDirect3DRMDevice3_QueryInterface(device3, &IID_IUnknown, (void **)&unknown);
3223 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice3 (hr = %x)\n", hr);
3224 IDirect3DRMDevice3_Release(device3);
3225 test_qi("device3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
3226 IUnknown_Release(unknown);
3228 IDirectDrawClipper_Release(clipper);
3229 IDirect3DRM3_Release(d3drm3);
3230 IDirect3DRM2_Release(d3drm2);
3231 IDirect3DRM_Release(d3drm1);
3232 DestroyWindow(window);
3236 static HRESULT CALLBACK surface_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
3238 IDirectDrawSurface **primary = context;
3240 if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
3242 *primary = surface;
3243 return DDENUMRET_CANCEL;
3245 IDirectDrawSurface_Release(surface);
3247 return DDENUMRET_OK;
3250 static void test_create_device_from_clipper1(void)
3252 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3253 IDirect3DRM *d3drm1 = NULL;
3254 IDirectDraw *ddraw = NULL;
3255 IUnknown *unknown = NULL;
3256 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3257 IDirect3DDevice *d3ddevice1 = NULL;
3258 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3259 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3260 IDirectDrawSurface7 *surface7 = NULL;
3261 DDSURFACEDESC desc, surface_desc;
3262 DWORD expected_flags, ret_val;
3263 HWND window;
3264 GUID driver = IID_IDirect3DRGBDevice;
3265 HRESULT hr;
3266 ULONG ref1, ref2, cref1, cref2;
3267 RECT rc;
3269 window = create_window();
3270 GetClientRect(window, &rc);
3271 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3272 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3273 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3274 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3276 hr = Direct3DRMCreate(&d3drm1);
3277 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3278 ref1 = get_refcount((IUnknown *)d3drm1);
3279 cref1 = get_refcount((IUnknown *)clipper);
3281 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 0, 0, &device1);
3282 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3283 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3285 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3286 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, NULL, &driver, 300, 200, &device1);
3287 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3289 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, NULL);
3290 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3292 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, &device1);
3293 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3294 ref2 = get_refcount((IUnknown *)d3drm1);
3295 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3296 cref2 = get_refcount((IUnknown *)clipper);
3297 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3298 ret_val = IDirect3DRMDevice_GetWidth(device1);
3299 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3300 ret_val = IDirect3DRMDevice_GetHeight(device1);
3301 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3303 /* Fetch immediate mode device in order to access render target */
3304 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3305 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3307 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3308 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3310 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3311 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3313 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3314 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3315 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3316 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3317 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3318 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3319 IUnknown_Release(unknown);
3320 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3321 NULL, &d3drm_primary, surface_callback);
3322 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3323 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3324 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3325 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3326 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3328 IDirectDrawClipper_Release(d3drm_clipper);
3329 IDirectDrawSurface_Release(d3drm_primary);
3330 IDirectDrawSurface7_Release(surface7);
3331 IDirectDraw_Release(ddraw);
3333 /* Check properties of render target and depth surface */
3334 surface_desc.dwSize = sizeof(surface_desc);
3335 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3336 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3338 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3339 surface_desc.dwWidth, surface_desc.dwHeight);
3340 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3341 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3342 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3343 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3345 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3346 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3347 desc.dwSize = sizeof(desc);
3348 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3349 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3350 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3351 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3353 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3354 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3356 desc.dwSize = sizeof(desc);
3357 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3358 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3360 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3361 desc.dwWidth, desc.dwHeight);
3362 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3363 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3364 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3365 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3366 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3368 /* Release old objects and check refcount of device and clipper */
3369 IDirectDrawSurface_Release(ds);
3370 ds = NULL;
3371 IDirectDrawSurface_Release(surface);
3372 surface = NULL;
3373 IDirect3DDevice_Release(d3ddevice1);
3374 d3ddevice1 = NULL;
3375 IDirect3DRMDevice_Release(device1);
3376 ref2 = get_refcount((IUnknown *)d3drm1);
3377 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3378 cref2 = get_refcount((IUnknown *)clipper);
3379 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3381 /* Test if render target format follows the screen format */
3382 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3383 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3384 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3385 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3387 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3388 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3389 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3391 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
3392 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3394 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3395 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3397 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3398 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3400 surface_desc.dwSize = sizeof(surface_desc);
3401 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3402 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3403 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3404 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3406 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3407 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3409 if (ds)
3410 IDirectDrawSurface_Release(ds);
3411 IDirectDrawSurface_Release(surface);
3412 IDirect3DDevice_Release(d3ddevice1);
3413 IDirect3DRMDevice_Release(device1);
3414 IDirect3DRM_Release(d3drm1);
3415 IDirectDrawClipper_Release(clipper);
3416 IDirectDraw_Release(ddraw);
3417 DestroyWindow(window);
3420 static void test_create_device_from_clipper2(void)
3422 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3423 IDirect3DRM *d3drm1 = NULL;
3424 IDirect3DRM2 *d3drm2 = NULL;
3425 IDirectDraw *ddraw = NULL;
3426 IUnknown *unknown = NULL;
3427 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
3428 IDirect3DDevice2 *d3ddevice2 = NULL;
3429 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3430 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3431 IDirectDrawSurface7 *surface7 = NULL;
3432 DDSURFACEDESC desc, surface_desc;
3433 DWORD expected_flags, ret_val;
3434 HWND window;
3435 GUID driver = IID_IDirect3DRGBDevice;
3436 HRESULT hr;
3437 ULONG ref1, ref2, ref3, cref1, cref2;
3438 RECT rc;
3440 window = create_window();
3441 GetClientRect(window, &rc);
3442 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3443 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3444 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3445 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3447 hr = Direct3DRMCreate(&d3drm1);
3448 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3449 ref1 = get_refcount((IUnknown *)d3drm1);
3450 cref1 = get_refcount((IUnknown *)clipper);
3452 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3453 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3454 ref2 = get_refcount((IUnknown *)d3drm2);
3456 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 0, 0, &device2);
3457 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3458 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
3460 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3461 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, NULL, &driver, 300, 200, &device2);
3462 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3464 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, NULL);
3465 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3467 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, &device2);
3468 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3469 ref3 = get_refcount((IUnknown *)d3drm1);
3470 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3471 ref3 = get_refcount((IUnknown *)d3drm2);
3472 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3473 cref2 = get_refcount((IUnknown *)clipper);
3474 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3475 ret_val = IDirect3DRMDevice2_GetWidth(device2);
3476 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3477 ret_val = IDirect3DRMDevice2_GetHeight(device2);
3478 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3480 /* Fetch immediate mode device in order to access render target */
3481 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3482 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3484 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3485 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3487 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3488 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3490 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3491 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3492 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3493 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3494 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3495 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3496 IUnknown_Release(unknown);
3497 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3498 NULL, &d3drm_primary, surface_callback);
3499 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3500 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3501 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3502 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3503 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3505 IDirectDrawClipper_Release(d3drm_clipper);
3506 IDirectDrawSurface_Release(d3drm_primary);
3507 IDirectDrawSurface7_Release(surface7);
3508 IDirectDraw_Release(ddraw);
3510 /* Check properties of render target and depth surface */
3511 surface_desc.dwSize = sizeof(surface_desc);
3512 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3513 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3515 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3516 surface_desc.dwWidth, surface_desc.dwHeight);
3517 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3518 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3519 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3520 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3522 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3523 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3524 desc.dwSize = sizeof(desc);
3525 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3526 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3527 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3528 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3530 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3531 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3533 desc.dwSize = sizeof(desc);
3534 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3535 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3537 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3538 desc.dwWidth, desc.dwHeight);
3539 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3540 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3541 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3542 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3543 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3545 /* Release old objects and check refcount of device and clipper */
3546 IDirectDrawSurface_Release(ds);
3547 ds = NULL;
3548 IDirectDrawSurface_Release(surface);
3549 surface = NULL;
3550 IDirect3DDevice2_Release(d3ddevice2);
3551 d3ddevice2 = NULL;
3552 IDirect3DRMDevice2_Release(device2);
3553 ref3 = get_refcount((IUnknown *)d3drm1);
3554 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3555 ref3 = get_refcount((IUnknown *)d3drm2);
3556 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3557 cref2 = get_refcount((IUnknown *)clipper);
3558 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3560 /* Test if render target format follows the screen format */
3561 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3562 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3563 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3564 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3566 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3567 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3568 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3570 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
3571 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3573 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3574 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3576 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3577 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3579 surface_desc.dwSize = sizeof(surface_desc);
3580 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3581 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3582 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3583 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3585 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3586 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3588 IDirectDrawSurface_Release(surface);
3589 IDirect3DDevice2_Release(d3ddevice2);
3590 IDirect3DRMDevice2_Release(device2);
3591 IDirect3DRM2_Release(d3drm2);
3592 IDirect3DRM_Release(d3drm1);
3593 IDirectDrawClipper_Release(clipper);
3594 IDirectDraw_Release(ddraw);
3595 DestroyWindow(window);
3598 static void test_create_device_from_clipper3(void)
3600 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3601 IDirect3DRM *d3drm1 = NULL;
3602 IDirect3DRM3 *d3drm3 = NULL;
3603 IDirectDraw *ddraw = NULL;
3604 IUnknown *unknown = NULL;
3605 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
3606 IDirect3DDevice2 *d3ddevice2 = NULL;
3607 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3608 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3609 IDirectDrawSurface7 *surface7 = NULL;
3610 DDSURFACEDESC desc, surface_desc;
3611 DWORD expected_flags, ret_val;
3612 HWND window;
3613 GUID driver = IID_IDirect3DRGBDevice;
3614 HRESULT hr;
3615 ULONG ref1, ref2, ref3, cref1, cref2;
3616 RECT rc;
3618 window = create_window();
3619 GetClientRect(window, &rc);
3620 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3621 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3622 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3623 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3625 hr = Direct3DRMCreate(&d3drm1);
3626 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3627 ref1 = get_refcount((IUnknown *)d3drm1);
3628 cref1 = get_refcount((IUnknown *)clipper);
3630 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3631 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3632 ref2 = get_refcount((IUnknown *)d3drm3);
3634 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 0, 0, &device3);
3635 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3636 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
3638 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3639 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, NULL, &driver, 300, 200, &device3);
3640 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3642 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, NULL);
3643 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3645 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, &device3);
3646 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3647 ref3 = get_refcount((IUnknown *)d3drm1);
3648 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3649 ref3 = get_refcount((IUnknown *)d3drm3);
3650 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3651 cref2 = get_refcount((IUnknown *)clipper);
3652 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3653 ret_val = IDirect3DRMDevice3_GetWidth(device3);
3654 ok(ret_val == 300, "Expected device width = 300, got %u.\n", ret_val);
3655 ret_val = IDirect3DRMDevice3_GetHeight(device3);
3656 ok(ret_val == 200, "Expected device height == 200, got %u.\n", ret_val);
3658 /* Fetch immediate mode device in order to access render target */
3659 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3660 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3662 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3663 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3665 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3666 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3668 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3669 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3670 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3671 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3672 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3673 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3674 IUnknown_Release(unknown);
3675 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3676 NULL, &d3drm_primary, surface_callback);
3677 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3678 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3679 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3680 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3681 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3683 IDirectDrawClipper_Release(d3drm_clipper);
3684 IDirectDrawSurface_Release(d3drm_primary);
3685 IDirectDrawSurface7_Release(surface7);
3686 IDirectDraw_Release(ddraw);
3688 /* Check properties of render target and depth surface */
3689 surface_desc.dwSize = sizeof(surface_desc);
3690 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3691 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3693 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3694 surface_desc.dwWidth, surface_desc.dwHeight);
3695 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3696 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3697 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3698 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3700 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3701 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3702 desc.dwSize = sizeof(desc);
3703 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3704 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3705 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3706 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3708 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3709 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3711 desc.dwSize = sizeof(desc);
3712 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3713 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3715 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3716 desc.dwWidth, desc.dwHeight);
3717 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3718 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3719 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3720 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3721 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3723 /* Release old objects and check refcount of device and clipper */
3724 IDirectDrawSurface_Release(ds);
3725 ds = NULL;
3726 IDirectDrawSurface_Release(surface);
3727 surface = NULL;
3728 IDirect3DDevice2_Release(d3ddevice2);
3729 d3ddevice2 = NULL;
3730 IDirect3DRMDevice3_Release(device3);
3731 ref3 = get_refcount((IUnknown *)d3drm1);
3732 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3733 ref3 = get_refcount((IUnknown *)d3drm3);
3734 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3735 cref2 = get_refcount((IUnknown *)clipper);
3736 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3738 /* Test if render target format follows the screen format */
3739 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3740 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3741 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3742 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3744 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3745 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3746 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3748 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
3749 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3751 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3752 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3754 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3755 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3757 surface_desc.dwSize = sizeof(surface_desc);
3758 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3759 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3760 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3761 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3763 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3764 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3766 IDirectDrawSurface_Release(surface);
3767 IDirect3DDevice2_Release(d3ddevice2);
3768 IDirect3DRMDevice3_Release(device3);
3769 IDirect3DRM3_Release(d3drm3);
3770 IDirect3DRM_Release(d3drm1);
3771 IDirectDrawClipper_Release(clipper);
3772 IDirectDraw_Release(ddraw);
3773 DestroyWindow(window);
3776 static void test_create_device_from_surface1(void)
3778 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3779 DDSURFACEDESC desc;
3780 IDirectDraw *ddraw = NULL;
3781 IDirect3DRM *d3drm1 = NULL;
3782 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3783 IDirect3DDevice *d3ddevice1 = NULL;
3784 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3785 DWORD expected_flags, ret_val;
3786 HWND window;
3787 GUID driver = IID_IDirect3DRGBDevice;
3788 ULONG ref1, ref2, surface_ref1, surface_ref2;
3789 RECT rc;
3790 BOOL use_sysmem_zbuffer = FALSE;
3791 HRESULT hr;
3793 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3794 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3796 window = create_window();
3797 GetClientRect(window, &rc);
3799 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3800 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3802 hr = Direct3DRMCreate(&d3drm1);
3803 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3804 ref1 = get_refcount((IUnknown *)d3drm1);
3806 /* Create a surface and use it to create the retained mode device. */
3807 memset(&desc, 0, sizeof(desc));
3808 desc.dwSize = sizeof(desc);
3809 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3810 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3811 desc.dwWidth = rc.right;
3812 desc.dwHeight = rc.bottom;
3814 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3815 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3817 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3818 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3819 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3820 IDirectDrawSurface_Release(surface);
3822 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3823 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3824 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3825 surface_ref1 = get_refcount((IUnknown *)surface);
3827 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, NULL);
3828 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
3829 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, NULL, &device1);
3830 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3831 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, NULL, surface, &device1);
3832 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3834 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3835 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3836 ref2 = get_refcount((IUnknown *)d3drm1);
3837 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3838 surface_ref2 = get_refcount((IUnknown *)surface);
3839 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
3840 ret_val = IDirect3DRMDevice_GetWidth(device1);
3841 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
3842 ret_val = IDirect3DRMDevice_GetHeight(device1);
3843 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
3845 /* Check if CreateDeviceFromSurface creates a primary surface */
3846 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3847 NULL, &d3drm_surface, surface_callback);
3848 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3849 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
3851 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3852 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3854 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3855 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3856 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3858 /* Check properties of attached depth surface */
3859 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
3860 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3862 memset(&desc, 0, sizeof(desc));
3863 desc.dwSize = sizeof(desc);
3864 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3865 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3867 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
3868 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3869 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3870 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3871 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3872 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3874 IDirectDrawSurface_Release(ds);
3875 IDirect3DDevice_Release(d3ddevice1);
3876 IDirectDrawSurface_Release(d3drm_surface);
3878 IDirect3DRMDevice_Release(device1);
3879 ref2 = get_refcount((IUnknown *)d3drm1);
3880 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3881 surface_ref2 = get_refcount((IUnknown *)surface);
3882 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
3883 surface_ref1, surface_ref2);
3884 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3885 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3886 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3887 ref1 = IDirectDrawSurface_Release(ds);
3888 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3889 ref1 = IDirectDrawSurface_Release(surface);
3890 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3892 memset(&desc, 0, sizeof(desc));
3893 desc.dwSize = sizeof(desc);
3894 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3895 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3896 desc.dwWidth = rc.right;
3897 desc.dwHeight = rc.bottom;
3899 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3900 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3902 memset(&desc, 0, sizeof(desc));
3903 desc.dwSize = sizeof(desc);
3904 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3905 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
3906 desc.dwZBufferBitDepth = 16;
3907 desc.dwWidth = rc.right;
3908 desc.dwHeight = rc.bottom;
3909 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
3910 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
3911 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
3912 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3914 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3915 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3917 hr = IDirect3DRMDevice2_GetDirect3DDevice(device1, &d3ddevice1);
3918 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3920 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3921 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3922 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3924 /* Check if depth surface matches the one we created */
3925 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3926 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3927 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3929 IDirectDrawSurface_Release(d3drm_ds);
3930 IDirectDrawSurface_Release(d3drm_surface);
3931 IDirectDrawSurface_Release(ds);
3933 IDirect3DDevice_Release(d3ddevice1);
3934 IDirect3DRMDevice_Release(device1);
3935 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3936 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3937 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3938 ref1 = IDirectDrawSurface_Release(ds);
3939 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3940 ref1 = IDirectDrawSurface_Release(surface);
3941 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3942 IDirect3DRM_Release(d3drm1);
3943 IDirectDraw_Release(ddraw);
3944 DestroyWindow(window);
3947 static void test_create_device_from_surface2(void)
3949 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3950 DDSURFACEDESC desc;
3951 IDirectDraw *ddraw = NULL;
3952 IDirect3DRM *d3drm1 = NULL;
3953 IDirect3DRM2 *d3drm2 = NULL;
3954 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
3955 IDirect3DDevice2 *d3ddevice2 = NULL;
3956 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3957 DWORD expected_flags, ret_val;
3958 HWND window;
3959 GUID driver = IID_IDirect3DRGBDevice;
3960 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
3961 RECT rc;
3962 BOOL use_sysmem_zbuffer = FALSE;
3963 HRESULT hr;
3965 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3966 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3968 window = create_window();
3969 GetClientRect(window, &rc);
3971 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3972 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3974 hr = Direct3DRMCreate(&d3drm1);
3975 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3976 ref1 = get_refcount((IUnknown *)d3drm1);
3978 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3979 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3980 ref2 = get_refcount((IUnknown *)d3drm2);
3982 /* Create a surface and use it to create the retained mode device. */
3983 memset(&desc, 0, sizeof(desc));
3984 desc.dwSize = sizeof(desc);
3985 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3986 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3987 desc.dwWidth = rc.right;
3988 desc.dwHeight = rc.bottom;
3990 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3991 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3993 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
3994 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3995 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
3996 IDirectDrawSurface_Release(surface);
3998 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3999 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4000 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4001 surface_ref1 = get_refcount((IUnknown *)surface);
4003 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, NULL);
4004 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
4005 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, NULL, &device2);
4006 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4007 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, NULL, surface, &device2);
4008 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4010 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
4011 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
4012 ref3 = get_refcount((IUnknown *)d3drm1);
4013 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4014 ref3 = get_refcount((IUnknown *)d3drm2);
4015 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4016 surface_ref2 = get_refcount((IUnknown *)surface);
4017 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
4018 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4019 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4020 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4021 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4023 /* Check if CreateDeviceFromSurface creates a primary surface */
4024 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4025 NULL, &d3drm_surface, surface_callback);
4026 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4027 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
4029 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4030 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4032 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4033 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4034 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4036 /* Check properties of attached depth surface */
4037 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
4038 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4040 memset(&desc, 0, sizeof(desc));
4041 desc.dwSize = sizeof(desc);
4042 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4043 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4045 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4046 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4047 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4048 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4049 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4050 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4052 IDirectDrawSurface_Release(ds);
4053 IDirect3DDevice2_Release(d3ddevice2);
4054 IDirectDrawSurface_Release(d3drm_surface);
4056 IDirect3DRMDevice2_Release(device2);
4057 ref3 = get_refcount((IUnknown *)d3drm1);
4058 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4059 ref3 = get_refcount((IUnknown *)d3drm2);
4060 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4061 surface_ref2 = get_refcount((IUnknown *)surface);
4062 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
4063 surface_ref1, surface_ref2);
4064 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4065 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4066 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4067 ref1 = IDirectDrawSurface_Release(ds);
4068 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4070 ref1 = IDirectDrawSurface_Release(surface);
4071 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4073 memset(&desc, 0, sizeof(desc));
4074 desc.dwSize = sizeof(desc);
4075 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4076 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4077 desc.dwWidth = rc.right;
4078 desc.dwHeight = rc.bottom;
4080 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4081 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4083 memset(&desc, 0, sizeof(desc));
4084 desc.dwSize = sizeof(desc);
4085 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4086 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
4087 desc.dwZBufferBitDepth = 16;
4088 desc.dwWidth = rc.right;
4089 desc.dwHeight = rc.bottom;
4090 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
4091 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
4092 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
4093 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4095 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
4096 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
4098 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4099 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4101 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4102 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4103 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4105 /* Check if depth surface matches the one we created */
4106 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4107 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4108 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4110 IDirectDrawSurface_Release(d3drm_ds);
4111 IDirectDrawSurface_Release(d3drm_surface);
4112 IDirectDrawSurface_Release(ds);
4114 IDirect3DDevice2_Release(d3ddevice2);
4115 IDirect3DRMDevice2_Release(device2);
4116 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4117 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4118 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4119 ref1 = IDirectDrawSurface_Release(ds);
4120 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4121 ref1 = IDirectDrawSurface_Release(surface);
4122 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4123 IDirect3DRM2_Release(d3drm2);
4124 IDirect3DRM_Release(d3drm1);
4125 IDirectDraw_Release(ddraw);
4126 DestroyWindow(window);
4129 static void test_create_device_from_surface3(void)
4131 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4132 DDSURFACEDESC desc;
4133 IDirectDraw *ddraw = NULL;
4134 IDirect3DRM *d3drm1 = NULL;
4135 IDirect3DRM3 *d3drm3 = NULL;
4136 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
4137 IDirect3DDevice2 *d3ddevice2 = NULL;
4138 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
4139 DWORD expected_flags, ret_val;
4140 HWND window;
4141 GUID driver = IID_IDirect3DRGBDevice;
4142 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
4143 RECT rc;
4144 BOOL use_sysmem_zbuffer = FALSE;
4145 HRESULT hr;
4147 hr = DirectDrawCreate(NULL, &ddraw, NULL);
4148 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4150 window = create_window();
4151 GetClientRect(window, &rc);
4153 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4154 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4156 hr = Direct3DRMCreate(&d3drm1);
4157 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4158 ref1 = get_refcount((IUnknown *)d3drm1);
4160 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
4161 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
4162 ref2 = get_refcount((IUnknown *)d3drm3);
4164 /* Create a surface and use it to create the retained mode device. */
4165 memset(&desc, 0, sizeof(desc));
4166 desc.dwSize = sizeof(desc);
4167 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4168 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
4169 desc.dwWidth = rc.right;
4170 desc.dwHeight = rc.bottom;
4172 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4173 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4175 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4176 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
4177 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
4178 IDirectDrawSurface_Release(surface);
4180 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
4181 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4182 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4183 surface_ref1 = get_refcount((IUnknown *)surface);
4185 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, NULL);
4186 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
4187 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, NULL, 0, &device3);
4188 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4189 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, NULL, surface, 0, &device3);
4190 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
4192 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4193 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4194 ref3 = get_refcount((IUnknown *)d3drm1);
4195 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4196 ref3 = get_refcount((IUnknown *)d3drm3);
4197 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4198 surface_ref2 = get_refcount((IUnknown *)surface);
4199 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
4200 ret_val = IDirect3DRMDevice3_GetWidth(device3);
4201 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4202 ret_val = IDirect3DRMDevice3_GetHeight(device3);
4203 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4205 /* Check if CreateDeviceFromSurface creates a primary surface */
4206 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4207 NULL, &d3drm_surface, surface_callback);
4208 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4209 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
4211 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4212 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4214 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4215 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4216 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4218 /* Check properties of attached depth surface */
4219 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
4220 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4222 memset(&desc, 0, sizeof(desc));
4223 desc.dwSize = sizeof(desc);
4224 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4225 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4227 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
4228 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4229 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4230 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4231 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4232 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4234 IDirectDrawSurface_Release(ds);
4235 IDirect3DDevice2_Release(d3ddevice2);
4236 IDirectDrawSurface_Release(d3drm_surface);
4237 IDirect3DRMDevice3_Release(device3);
4239 ref3 = get_refcount((IUnknown *)d3drm1);
4240 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4241 ref3 = get_refcount((IUnknown *)d3drm3);
4242 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4243 surface_ref2 = get_refcount((IUnknown *)surface);
4244 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
4245 surface_ref1, surface_ref2);
4246 /* In version 3, d3drm will destroy all references of the depth surface it created internally. */
4247 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4248 todo_wine ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x.\n", hr);
4249 if (SUCCEEDED(hr))
4250 IDirectDrawSurface_Release(ds);
4251 ref1 = IDirectDrawSurface_Release(surface);
4252 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4254 memset(&desc, 0, sizeof(desc));
4255 desc.dwSize = sizeof(desc);
4256 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4257 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4258 desc.dwWidth = rc.right;
4259 desc.dwHeight = rc.bottom;
4261 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4262 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4264 memset(&desc, 0, sizeof(desc));
4265 desc.dwSize = sizeof(desc);
4266 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4267 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
4268 desc.dwZBufferBitDepth = 16;
4269 desc.dwWidth = rc.right;
4270 desc.dwHeight = rc.bottom;
4271 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
4272 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
4273 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
4274 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4276 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
4277 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4279 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4280 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4282 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4283 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4284 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4286 /* Check if depth surface matches the one we created */
4287 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4288 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4289 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4291 IDirectDrawSurface_Release(d3drm_ds);
4292 IDirectDrawSurface_Release(d3drm_surface);
4293 IDirectDrawSurface_Release(ds);
4294 IDirect3DDevice2_Release(d3ddevice2);
4295 IDirect3DRMDevice3_Release(device3);
4296 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4297 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4298 /* The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4299 ref1 = IDirectDrawSurface_Release(ds);
4300 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4302 /* What happens if we pass no flags and still attach our own depth surface? */
4303 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
4304 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4306 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4307 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4309 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4310 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4311 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4313 /* Check if depth surface matches the one we created */
4314 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4315 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4316 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4318 IDirectDrawSurface_Release(d3drm_ds);
4319 IDirectDrawSurface_Release(d3drm_surface);
4320 IDirect3DDevice2_Release(d3ddevice2);
4321 IDirect3DRMDevice3_Release(device3);
4322 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
4323 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4324 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
4325 ref1 = IDirectDrawSurface_Release(ds);
4326 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
4327 ref1 = IDirectDrawSurface_Release(surface);
4328 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4330 memset(&desc, 0, sizeof(desc));
4331 desc.dwSize = sizeof(desc);
4332 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4333 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4334 desc.dwWidth = rc.right;
4335 desc.dwHeight = rc.bottom;
4337 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
4338 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4340 /* What happens if we don't pass D3DRMDEVICE_NOZBUFFER and still not attach our own depth surface? */
4341 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
4342 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
4344 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4345 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4347 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
4348 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4349 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
4351 /* Check if depth surface matches the one we created */
4352 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
4353 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x).\n", hr);
4354 IDirectDrawSurface_Release(d3drm_surface);
4356 IDirect3DDevice2_Release(d3ddevice2);
4357 IDirect3DRMDevice3_Release(device3);
4358 ref1 = IDirectDrawSurface_Release(surface);
4359 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
4360 IDirect3DRM3_Release(d3drm3);
4361 IDirect3DRM_Release(d3drm1);
4362 IDirectDraw_Release(ddraw);
4363 DestroyWindow(window);
4366 static IDirect3DDevice *create_device1(IDirectDraw *ddraw, HWND window, IDirectDrawSurface **ds)
4368 static const DWORD z_depths[] = { 32, 24, 16 };
4369 IDirectDrawSurface *surface;
4370 IDirect3DDevice *device = NULL;
4371 DDSURFACEDESC surface_desc;
4372 unsigned int i;
4373 HRESULT hr;
4374 RECT rc;
4376 GetClientRect(window, &rc);
4377 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4378 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4380 memset(&surface_desc, 0, sizeof(surface_desc));
4381 surface_desc.dwSize = sizeof(surface_desc);
4382 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4383 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4384 surface_desc.dwWidth = rc.right;
4385 surface_desc.dwHeight = rc.bottom;
4387 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4388 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4390 /* We used to use EnumDevices() for this, but it seems
4391 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
4392 * relationship with reality. */
4393 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
4395 memset(&surface_desc, 0, sizeof(surface_desc));
4396 surface_desc.dwSize = sizeof(surface_desc);
4397 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4398 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4399 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
4400 surface_desc.dwWidth = rc.right;
4401 surface_desc.dwHeight = rc.bottom;
4402 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, ds, NULL)))
4403 continue;
4405 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
4406 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4407 if (FAILED(hr))
4409 IDirectDrawSurface_Release(*ds);
4410 continue;
4413 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device)))
4414 break;
4416 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
4417 IDirectDrawSurface_Release(*ds);
4418 *ds = NULL;
4421 IDirectDrawSurface_Release(surface);
4422 return device;
4425 static void test_create_device_from_d3d1(void)
4427 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
4428 IDirect3D *d3d1 = NULL, *temp_d3d1;
4429 IDirect3DRM *d3drm1 = NULL;
4430 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
4431 IDirect3DRMDevice2 *device2;
4432 IDirect3DRMDevice3 *device3;
4433 IDirect3DDevice *d3ddevice1 = NULL, *d3drm_d3ddevice1 = NULL, *temp_d3ddevice1;
4434 IDirect3DDevice2 *d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4435 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4436 DWORD expected_flags, ret_val;
4437 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4438 DDSURFACEDESC desc;
4439 RECT rc;
4440 HWND window;
4441 ULONG ref1, ref2, ref3, ref4, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
4442 HRESULT hr;
4444 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4445 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4447 window = create_window();
4448 GetClientRect(window, &rc);
4450 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
4451 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4452 d3d_ref1 = get_refcount((IUnknown *)d3d1);
4454 /* Create the immediate mode device */
4455 d3ddevice1 = create_device1(ddraw1, window, &ds);
4456 if (d3ddevice1 == NULL)
4458 win_skip("Cannot create IM device, skipping tests.\n");
4459 IDirect3D_Release(d3d1);
4460 IDirectDraw_Release(ddraw1);
4461 return;
4463 device_ref1 = get_refcount((IUnknown *)d3ddevice1);
4465 hr = Direct3DRMCreate(&d3drm1);
4466 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4467 ref1 = get_refcount((IUnknown *)d3drm1);
4469 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, NULL, d3ddevice1, &device1);
4470 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4471 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
4472 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, NULL, &device1);
4473 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4474 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, NULL);
4475 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4477 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, &device1);
4478 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice interface (hr = %x)\n", hr);
4479 ref2 = get_refcount((IUnknown *)d3drm1);
4480 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
4481 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4482 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4483 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4484 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4485 ret_val = IDirect3DRMDevice_GetWidth(device1);
4486 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4487 ret_val = IDirect3DRMDevice_GetHeight(device1);
4488 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4490 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
4491 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
4492 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4493 ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
4494 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4495 IDirect3DRMDevice2_Release(device2);
4497 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4498 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
4499 ok(hr == DD_OK, "Cannot get IDirect3DRMDevice3 Interface (hr = %x).\n", hr);
4500 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4501 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4502 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4503 IDirect3DRMDevice3_Release(device3);
4505 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4506 NULL, &surface, surface_callback);
4507 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4508 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4510 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
4511 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
4512 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice1, d3drm_d3ddevice1);
4514 /* Check properties of render target and depth surfaces */
4515 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
4516 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4518 memset(&desc, 0, sizeof(desc));
4519 desc.dwSize = sizeof(desc);
4520 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4521 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4523 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4524 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4525 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4526 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4527 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4528 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4530 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4531 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4532 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4534 desc.dwSize = sizeof(desc);
4535 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4536 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4538 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4539 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4540 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4541 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4542 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4544 IDirectDrawSurface_Release(d3drm_ds);
4545 IDirectDrawSurface_Release(ds);
4546 IDirectDrawSurface_Release(surface);
4547 IDirect3DDevice_Release(d3drm_d3ddevice1);
4548 IDirect3DRMDevice_Release(device1);
4549 ref2 = get_refcount((IUnknown *)d3drm1);
4550 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
4551 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4552 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4554 /* InitFromD3D tests */
4555 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice, (void **)&device1);
4556 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
4558 hr = IDirect3DRMDevice_InitFromD3D(device1, NULL, d3ddevice1);
4559 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4560 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, NULL);
4561 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4563 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4564 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice interface (hr = %#x)\n", hr);
4565 ref2 = get_refcount((IUnknown *)d3drm1);
4566 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
4567 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4568 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4569 device_ref1, device_ref2);
4570 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4571 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4572 ret_val = IDirect3DRMDevice_GetWidth(device1);
4573 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4574 ret_val = IDirect3DRMDevice_GetHeight(device1);
4575 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4577 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4578 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4579 ref3 = get_refcount((IUnknown *)d3drm1);
4580 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4581 ref3 = get_refcount((IUnknown *)d3ddevice1);
4582 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4583 ref3 = get_refcount((IUnknown *)d3d1);
4584 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4585 /* Release leaked references */
4586 while (IDirect3DRM_Release(d3drm1) > ref2);
4587 while (IDirect3DDevice_Release(d3ddevice1) > device_ref2);
4588 while (IDirect3D_Release(d3d1) > d3d_ref2);
4590 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
4591 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
4592 ref4 = get_refcount((IUnknown *)temp_ddraw1);
4594 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D, (void **)&temp_d3d1);
4595 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
4596 temp_d3ddevice1 = create_device1(temp_ddraw1, window, &surface);
4597 hr = IDirect3DRMDevice_InitFromD3D(device1, temp_d3d1, temp_d3ddevice1);
4598 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4599 ref3 = get_refcount((IUnknown *)d3drm1);
4600 ok(ref3 > ref2, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4601 ref3 = get_refcount((IUnknown *)temp_d3ddevice1);
4602 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4603 ref3 = get_refcount((IUnknown *)temp_d3d1);
4604 todo_wine ok(ref3 < d3d_ref2, "Expected ref3 < d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4605 /* Release leaked references */
4606 while (IDirect3DRM_Release(d3drm1) > ref2);
4607 while (IDirect3DDevice_Release(temp_d3ddevice1) > 0);
4608 while (IDirect3D_Release(temp_d3d1) > ref4);
4609 IDirectDrawSurface_Release(surface);
4610 IDirectDraw_Release(temp_ddraw1);
4612 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4613 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
4614 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
4615 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
4616 ok(SUCCEEDED(hr), "Expected hr == D3DRM_OK, got %#x.\n", hr);
4617 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4618 IDirect3DRMDevice2_Release(device2);
4620 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
4621 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice3, (void **)&device3);
4622 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 Interface (hr = %#x).\n", hr);
4623 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
4624 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4625 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
4626 IDirect3DRMDevice3_Release(device3);
4628 surface = NULL;
4629 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4630 NULL, &surface, surface_callback);
4631 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
4632 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4634 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
4635 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice interface (hr = %#x).\n", hr);
4636 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n",
4637 d3ddevice1, d3drm_d3ddevice1);
4639 /* Check properties of render target and depth surfaces */
4640 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
4641 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
4643 memset(&desc, 0, sizeof(desc));
4644 desc.dwSize = sizeof(desc);
4645 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4646 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %#x).\n", hr);
4648 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4649 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4650 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
4651 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4652 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4653 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4655 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4656 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
4657 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4659 desc.dwSize = sizeof(desc);
4660 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4661 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %#x).\n", hr);
4663 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4664 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4665 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %#x, got %#x.\n",
4666 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4667 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4668 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
4670 IDirectDrawSurface_Release(d3drm_ds);
4671 IDirectDrawSurface_Release(ds);
4672 IDirectDrawSurface_Release(surface);
4673 IDirect3DDevice_Release(d3drm_d3ddevice1);
4674 IDirect3DRMDevice_Release(device1);
4675 ref2 = get_refcount((IUnknown *)d3drm1);
4676 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
4677 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4678 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4679 device_ref1, device_ref2);
4680 d3d_ref2 = get_refcount((IUnknown *)d3d1);
4681 todo_wine ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1,
4682 d3d_ref2);
4684 IDirect3DRM_Release(d3drm1);
4685 IDirect3DDevice_Release(d3ddevice1);
4686 IDirect3D_Release(d3d1);
4687 IDirectDraw_Release(ddraw1);
4688 DestroyWindow(window);
4691 static IDirect3DDevice2 *create_device2(IDirectDraw2 *ddraw, HWND window, IDirectDrawSurface **ds)
4693 static const DWORD z_depths[] = { 32, 24, 16 };
4694 IDirectDrawSurface *surface;
4695 IDirect3DDevice2 *device = NULL;
4696 DDSURFACEDESC surface_desc;
4697 IDirect3D2 *d3d;
4698 unsigned int i;
4699 HRESULT hr;
4700 RECT rc;
4702 GetClientRect(window, &rc);
4703 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4704 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4706 memset(&surface_desc, 0, sizeof(surface_desc));
4707 surface_desc.dwSize = sizeof(surface_desc);
4708 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4709 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4710 surface_desc.dwWidth = rc.right;
4711 surface_desc.dwHeight = rc.bottom;
4713 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4714 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4716 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
4717 if (FAILED(hr))
4719 IDirectDrawSurface_Release(surface);
4720 *ds = NULL;
4721 return NULL;
4724 /* We used to use EnumDevices() for this, but it seems
4725 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
4726 * relationship with reality. */
4727 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
4729 memset(&surface_desc, 0, sizeof(surface_desc));
4730 surface_desc.dwSize = sizeof(surface_desc);
4731 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4732 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4733 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
4734 surface_desc.dwWidth = rc.right;
4735 surface_desc.dwHeight = rc.bottom;
4736 if (FAILED(IDirectDraw2_CreateSurface(ddraw, &surface_desc, ds, NULL)))
4737 continue;
4739 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
4740 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4741 if (FAILED(hr))
4743 IDirectDrawSurface_Release(*ds);
4744 continue;
4747 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device)))
4748 break;
4750 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
4751 IDirectDrawSurface_Release(*ds);
4752 *ds = NULL;
4755 IDirect3D2_Release(d3d);
4756 IDirectDrawSurface_Release(surface);
4757 return device;
4760 static void test_create_device_from_d3d2(void)
4762 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
4763 IDirectDraw2 *ddraw2 = NULL, *temp_ddraw2;
4764 IDirect3D* d3d1;
4765 IDirect3D2 *d3d2 = NULL, *temp_d3d2;
4766 IDirect3DRM *d3drm1 = NULL;
4767 IDirect3DRM2 *d3drm2 = NULL;
4768 IDirect3DRMDevice *device1;
4769 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
4770 IDirect3DDevice *d3ddevice1;
4771 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL, *temp_d3ddevice2;
4772 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4773 DWORD expected_flags, ret_val;
4774 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4775 DDSURFACEDESC desc;
4776 RECT rc;
4777 HWND window;
4778 ULONG ref1, ref2, ref3, ref4, ref5, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
4779 HRESULT hr;
4781 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4782 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4784 window = create_window();
4785 GetClientRect(window, &rc);
4787 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
4788 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4789 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
4790 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
4791 d3d_ref1 = get_refcount((IUnknown *)d3d2);
4793 /* Create the immediate mode device */
4794 d3ddevice2 = create_device2(ddraw2, window, &ds);
4795 if (d3ddevice2 == NULL)
4797 win_skip("Cannot create IM device, skipping tests.\n");
4798 IDirect3D2_Release(d3d2);
4799 IDirectDraw2_Release(ddraw2);
4800 IDirectDraw_Release(ddraw1);
4801 return;
4803 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
4805 hr = Direct3DRMCreate(&d3drm1);
4806 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4807 ref1 = get_refcount((IUnknown *)d3drm1);
4809 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
4810 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
4811 ref2 = get_refcount((IUnknown *)d3drm2);
4813 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, NULL, d3ddevice2, &device2);
4814 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4815 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
4816 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, NULL, &device2);
4817 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4818 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, NULL);
4819 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4821 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, &device2);
4822 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice2 interface (hr = %x)\n", hr);
4823 ref3 = get_refcount((IUnknown *)d3drm1);
4824 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4825 ref3 = get_refcount((IUnknown *)d3drm2);
4826 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4827 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4828 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4829 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4830 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4831 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4832 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4833 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4834 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4836 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4837 NULL, &surface, surface_callback);
4838 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4839 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4841 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
4842 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4843 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
4845 /* Check properties of render target and depth surfaces */
4846 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
4847 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4849 memset(&desc, 0, sizeof(desc));
4850 desc.dwSize = sizeof(desc);
4851 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4852 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4854 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4855 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4856 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4857 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4858 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4859 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4861 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4862 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4863 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4865 desc.dwSize = sizeof(desc);
4866 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4867 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4869 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4870 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4871 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4872 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4873 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4875 IDirectDrawSurface_Release(d3drm_ds);
4876 IDirectDrawSurface_Release(ds);
4877 IDirectDrawSurface_Release(surface);
4878 IDirect3DDevice2_Release(d3drm_d3ddevice2);
4879 IDirect3DRMDevice2_Release(device2);
4880 ref3 = get_refcount((IUnknown *)d3drm1);
4881 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4882 ref3 = get_refcount((IUnknown *)d3drm2);
4883 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4884 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4885 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4886 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4887 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4889 /* InitFromD3D tests */
4890 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice2, (void **)&device2);
4891 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %#x).\n", hr);
4893 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
4894 ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %x).\n", hr);
4895 if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
4897 hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, d3ddevice1);
4898 ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
4899 hr = IDirect3DRMDevice2_InitFromD3D(device2, NULL, d3ddevice1);
4900 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4901 hr = IDirect3DRMDevice2_InitFromD3D(device2, d3d1, NULL);
4902 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4903 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IDirect3DRMDevice, (void **)&device1);
4904 ok(SUCCEEDED(hr), "Cannot obtain IDirect3DRMDevice interface (hr = %#x).\n", hr);
4905 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
4906 todo_wine ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
4907 IDirect3DRMDevice_Release(device1);
4908 if (SUCCEEDED(hr))
4910 IDirect3DRMDevice_Release(device1);
4911 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice2,
4912 (void **)&device2);
4913 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %#x).\n", hr);
4916 IDirect3D_Release(d3d1);
4917 IDirect3DDevice_Release(d3ddevice1);
4919 hr = IDirect3DRMDevice2_InitFromD3D2(device2, NULL, d3ddevice2);
4920 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4921 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, NULL);
4922 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
4924 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, d3ddevice2);
4925 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice2 interface (hr = %#x)\n", hr);
4926 ref4 = get_refcount((IUnknown *)d3drm1);
4927 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
4928 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4929 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
4930 device_ref1, device_ref2);
4931 d3d_ref2 = get_refcount((IUnknown *)d3d2);
4932 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
4933 ret_val = IDirect3DRMDevice2_GetWidth(device2);
4934 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
4935 ret_val = IDirect3DRMDevice2_GetHeight(device2);
4936 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
4938 hr = IDirect3DRMDevice2_InitFromD3D2(device2, d3d2, d3ddevice2);
4939 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4940 ref3 = get_refcount((IUnknown *)d3drm1);
4941 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4942 ref3 = get_refcount((IUnknown *)d3ddevice2);
4943 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4944 ref3 = get_refcount((IUnknown *)d3d2);
4945 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4946 /* Release leaked references */
4947 while (IDirect3DRM_Release(d3drm1) > ref4);
4948 while (IDirect3DDevice2_Release(d3ddevice2) > device_ref2);
4949 while (IDirect3D2_Release(d3d2) > d3d_ref2);
4951 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
4952 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
4953 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D2, (void **)&temp_d3d2);
4954 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
4955 ref5 = get_refcount((IUnknown *)temp_d3d2);
4957 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirectDraw2, (void **)&temp_ddraw2);
4958 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
4960 temp_d3ddevice2 = create_device2(temp_ddraw2, window, &surface);
4961 hr = IDirect3DRMDevice2_InitFromD3D2(device2, temp_d3d2, temp_d3ddevice2);
4962 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
4963 ref3 = get_refcount((IUnknown *)d3drm1);
4964 ok(ref3 > ref4, "expected ref3 > ref4, got ref3 = %u , ref4 = %u.\n", ref3, ref4);
4965 ref3 = get_refcount((IUnknown *)temp_d3ddevice2);
4966 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
4967 ref3 = get_refcount((IUnknown *)temp_d3d2);
4968 ok(ref3 == d3d_ref2, "Expected ref3 == d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
4969 /* Release leaked references */
4970 while (IDirect3DRM_Release(d3drm1) > ref4);
4971 while (IDirect3DDevice2_Release(temp_d3ddevice2) > 0);
4972 while (IDirect3D2_Release(temp_d3d2) >= ref5);
4973 IDirectDrawSurface_Release(surface);
4974 IDirectDraw2_Release(temp_ddraw2);
4975 IDirectDraw_Release(temp_ddraw1);
4977 surface = NULL;
4978 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4979 NULL, &surface, surface_callback);
4980 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
4981 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4983 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
4984 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
4985 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2,
4986 d3drm_d3ddevice2);
4988 /* Check properties of render target and depth surfaces */
4989 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
4990 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
4992 memset(&desc, 0, sizeof(desc));
4993 desc.dwSize = sizeof(desc);
4994 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4995 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %#x).\n", hr);
4997 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4998 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4999 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
5000 "Expected caps containing %#x, got %#x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5001 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5002 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5004 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5005 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
5006 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5008 desc.dwSize = sizeof(desc);
5009 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5010 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %x).\n", hr);
5012 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5013 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5014 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %#x, got %#x.\n",
5015 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5016 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5017 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5019 IDirectDrawSurface_Release(d3drm_ds);
5020 IDirectDrawSurface_Release(ds);
5021 IDirectDrawSurface_Release(surface);
5022 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5023 IDirect3DRMDevice2_Release(device2);
5024 ref3 = get_refcount((IUnknown *)d3drm1);
5025 ok(ref1 == ref3, "Expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5026 ref3 = get_refcount((IUnknown *)d3drm2);
5027 ok(ref3 == ref2, "Expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5028 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5029 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5030 device_ref1, device_ref2);
5031 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5032 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5034 IDirect3DRM2_Release(d3drm2);
5035 IDirect3DRM_Release(d3drm1);
5036 IDirect3DDevice2_Release(d3ddevice2);
5037 IDirect3D2_Release(d3d2);
5038 IDirectDraw2_Release(ddraw2);
5039 IDirectDraw_Release(ddraw1);
5040 DestroyWindow(window);
5043 static void test_create_device_from_d3d3(void)
5045 IDirectDraw *ddraw1 = NULL, *temp_ddraw1;
5046 IDirectDraw2 *ddraw2 = NULL, *temp_ddraw2;
5047 IDirect3D *d3d1;
5048 IDirect3D2 *d3d2 = NULL, *temp_d3d2;
5049 IDirect3DRM *d3drm1 = NULL;
5050 IDirect3DRM3 *d3drm3 = NULL;
5051 IDirect3DRMDevice *device1;
5052 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
5053 IDirect3DDevice *d3ddevice1;
5054 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL, *temp_d3ddevice2;
5055 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
5056 DWORD expected_flags, ret_val;
5057 DDSCAPS caps = { DDSCAPS_ZBUFFER };
5058 DDSURFACEDESC desc;
5059 RECT rc;
5060 HWND window;
5061 ULONG ref1, ref2, ref3, ref4, ref5, device_ref1, device_ref2, d3d_ref1, d3d_ref2;
5062 HRESULT hr;
5064 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
5065 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
5067 window = create_window();
5068 GetClientRect(window, &rc);
5070 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
5071 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
5072 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
5073 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
5074 d3d_ref1 = get_refcount((IUnknown *)d3d2);
5076 /* Create the immediate mode device */
5077 d3ddevice2 = create_device2(ddraw2, window, &ds);
5078 if (d3ddevice2 == NULL)
5080 win_skip("Cannot create IM device, skipping tests.\n");
5081 IDirect3D2_Release(d3d2);
5082 IDirectDraw2_Release(ddraw2);
5083 IDirectDraw_Release(ddraw1);
5084 return;
5086 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
5088 hr = Direct3DRMCreate(&d3drm1);
5089 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
5090 ref1 = get_refcount((IUnknown *)d3drm1);
5092 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5093 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
5094 ref2 = get_refcount((IUnknown *)d3drm3);
5096 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, NULL, d3ddevice2, &device3);
5097 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5098 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
5099 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, NULL, &device3);
5100 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5101 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, NULL);
5102 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
5104 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, &device3);
5105 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice3 interface (hr = %x)\n", hr);
5106 ref3 = get_refcount((IUnknown *)d3drm1);
5107 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
5108 ref3 = get_refcount((IUnknown *)d3drm3);
5109 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5110 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5111 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
5112 ret_val = IDirect3DRMDevice3_GetWidth(device3);
5113 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
5114 ret_val = IDirect3DRMDevice3_GetHeight(device3);
5115 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
5117 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
5118 NULL, &surface, surface_callback);
5119 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
5120 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
5122 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
5123 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
5124 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
5126 /* Check properties of render target and depth surfaces */
5127 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
5128 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
5130 memset(&desc, 0, sizeof(desc));
5131 desc.dwSize = sizeof(desc);
5132 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
5133 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
5135 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5136 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5137 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
5138 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5139 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5140 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
5142 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5143 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
5144 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5146 desc.dwSize = sizeof(desc);
5147 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5148 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
5150 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5151 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5152 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5153 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5154 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
5156 IDirectDrawSurface_Release(d3drm_ds);
5157 IDirectDrawSurface_Release(ds);
5158 IDirectDrawSurface_Release(surface);
5159 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5160 IDirect3DRMDevice3_Release(device3);
5161 ref3 = get_refcount((IUnknown *)d3drm1);
5162 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5163 ref3 = get_refcount((IUnknown *)d3drm3);
5164 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5165 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5166 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
5167 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5168 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5170 /* InitFromD3D tests */
5171 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice3, (void **)&device3);
5172 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5174 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
5175 ok(SUCCEEDED(hr), "Cannot get IDirect3D interface (hr = %#x).\n", hr);
5176 if (SUCCEEDED(hr = IDirect3DDevice2_QueryInterface(d3ddevice2, &IID_IDirect3DDevice, (void **)&d3ddevice1)))
5178 hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, d3ddevice1);
5179 ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
5180 hr = IDirect3DRMDevice3_InitFromD3D(device3, NULL, d3ddevice1);
5181 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5182 hr = IDirect3DRMDevice3_InitFromD3D(device3, d3d1, NULL);
5183 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5184 hr = IDirect3DRMDevice3_QueryInterface(device3, &IID_IDirect3DRMDevice, (void **)&device1);
5185 ok(SUCCEEDED(hr), "Cannot obtain IDirect3DRMDevice interface (hr = %#x).\n", hr);
5186 hr = IDirect3DRMDevice_InitFromD3D(device1, d3d1, d3ddevice1);
5187 todo_wine ok(hr == E_NOINTERFACE, "Expected hr == E_NOINTERFACE, got %#x.\n", hr);
5188 IDirect3DRMDevice_Release(device1);
5189 if (SUCCEEDED(hr))
5191 IDirect3DRMDevice_Release(device1);
5192 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMDevice, NULL, &IID_IDirect3DRMDevice3,
5193 (void **)&device3);
5194 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5197 IDirect3D_Release(d3d1);
5198 IDirect3DDevice_Release(d3ddevice1);
5200 hr = IDirect3DRMDevice3_InitFromD3D2(device3, NULL, d3ddevice2);
5201 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5202 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, NULL);
5203 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
5205 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, d3ddevice2);
5206 ok(SUCCEEDED(hr), "Failed to initialise IDirect3DRMDevice2 interface (hr = %#x)\n", hr);
5207 ref4 = get_refcount((IUnknown *)d3drm1);
5208 ok(ref4 > ref1, "Expected ref4 > ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
5209 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5210 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5211 device_ref1, device_ref2);
5212 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5213 ok(d3d_ref2 > d3d_ref1, "Expected d3d_ref2 > d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5214 ret_val = IDirect3DRMDevice3_GetWidth(device3);
5215 ok(ret_val == rc.right, "Expected device width = 300, got %u.\n", ret_val);
5216 ret_val = IDirect3DRMDevice3_GetHeight(device3);
5217 ok(ret_val == rc.bottom, "Expected device height == 200, got %u.\n", ret_val);
5219 hr = IDirect3DRMDevice3_InitFromD3D2(device3, d3d2, d3ddevice2);
5220 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
5221 ref3 = get_refcount((IUnknown *)d3drm1);
5222 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
5223 ref3 = get_refcount((IUnknown *)d3ddevice2);
5224 ok(ref3 > device_ref2, "Expected ref3 > device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
5225 ref3 = get_refcount((IUnknown *)d3d2);
5226 ok(ref3 > d3d_ref2, "Expected ref3 > d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
5227 /* Release leaked references */
5228 while (IDirect3DRM_Release(d3drm1) > ref4);
5229 while (IDirect3DDevice2_Release(d3ddevice2) > device_ref2);
5230 while (IDirect3D2_Release(d3d2) > d3d_ref2);
5232 hr = DirectDrawCreate(NULL, &temp_ddraw1, NULL);
5233 ok(SUCCEEDED(hr), "Cannot get IDirectDraw interface (hr = %#x).\n", hr);
5234 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirect3D2, (void **)&temp_d3d2);
5235 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %#x).\n", hr);
5236 ref5 = get_refcount((IUnknown *)temp_d3d2);
5238 hr = IDirectDraw_QueryInterface(temp_ddraw1, &IID_IDirectDraw2, (void **)&temp_ddraw2);
5239 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
5241 temp_d3ddevice2 = create_device2(temp_ddraw2, window, &surface);
5242 hr = IDirect3DRMDevice3_InitFromD3D2(device3, temp_d3d2, temp_d3ddevice2);
5243 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
5244 ref3 = get_refcount((IUnknown *)d3drm1);
5245 ok(ref3 > ref4, "expected ref3 > ref4, got ref3 = %u , ref4 = %u.\n", ref3, ref4);
5246 ref3 = get_refcount((IUnknown *)temp_d3ddevice2);
5247 ok(ref3 == device_ref2, "Expected ref3 == device_ref2, got ref3 = %u, device_ref2 = %u.\n", ref3, device_ref2);
5248 ref3 = get_refcount((IUnknown *)temp_d3d2);
5249 ok(ref3 == d3d_ref2, "Expected ref3 == d3d_ref2, got ref3 = %u, d3d_ref2 = %u.\n", ref3, d3d_ref2);
5250 /* Release leaked references */
5251 while (IDirect3DRM_Release(d3drm1) > ref4);
5252 while (IDirect3DDevice2_Release(temp_d3ddevice2) > 0);
5253 while (IDirect3D2_Release(temp_d3d2) >= ref5);
5254 IDirectDrawSurface_Release(surface);
5255 IDirectDraw2_Release(temp_ddraw2);
5256 IDirectDraw_Release(temp_ddraw1);
5258 surface = NULL;
5259 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
5260 NULL, &surface, surface_callback);
5261 ok(SUCCEEDED(hr), "Failed to enumerate surfaces (hr = %#x).\n", hr);
5262 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
5264 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
5265 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
5266 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2,
5267 d3drm_d3ddevice2);
5269 /* Check properties of render target and depth surfaces */
5270 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
5271 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
5273 memset(&desc, 0, sizeof(desc));
5274 desc.dwSize = sizeof(desc);
5275 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
5276 ok(SUCCEEDED(hr), "Cannot get surface desc structure (hr = %x).\n", hr);
5278 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5279 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5280 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE),
5281 "Expected caps containing %#x, got %#x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
5282 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5283 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5285 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
5286 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
5287 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
5289 desc.dwSize = sizeof(desc);
5290 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
5291 ok(SUCCEEDED(hr), "Cannot get z surface desc structure (hr = %x).\n", hr);
5293 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
5294 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
5295 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %#x.\n",
5296 DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
5297 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
5298 ok(desc.dwFlags == expected_flags, "Expected %#x for flags, got %#x.\n", expected_flags, desc.dwFlags);
5300 IDirectDrawSurface_Release(d3drm_ds);
5301 IDirectDrawSurface_Release(ds);
5302 IDirectDrawSurface_Release(surface);
5303 IDirect3DDevice2_Release(d3drm_d3ddevice2);
5304 IDirect3DRMDevice3_Release(device3);
5305 ref3 = get_refcount((IUnknown *)d3drm1);
5306 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
5307 ref3 = get_refcount((IUnknown *)d3drm3);
5308 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
5309 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
5310 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n",
5311 device_ref1, device_ref2);
5312 d3d_ref2 = get_refcount((IUnknown *)d3d2);
5313 ok(d3d_ref2 == d3d_ref1, "Expected d3d_ref2 == d3d_ref1, got d3d_ref1 = %u, d3d_ref2 = %u.\n", d3d_ref1, d3d_ref2);
5315 IDirect3DRM3_Release(d3drm3);
5316 IDirect3DRM_Release(d3drm1);
5317 IDirect3DDevice2_Release(d3ddevice2);
5318 IDirect3D2_Release(d3d2);
5319 IDirectDraw2_Release(ddraw2);
5320 IDirectDraw_Release(ddraw1);
5321 DestroyWindow(window);
5324 static char *create_bitmap(unsigned int w, unsigned int h, BOOL palettized)
5326 unsigned int bpp = palettized ? 8 : 24;
5327 BITMAPFILEHEADER file_header;
5328 DWORD written, size, ret;
5329 unsigned char *buffer;
5330 char path[MAX_PATH];
5331 unsigned int i, j;
5332 BITMAPINFO *info;
5333 char *filename;
5334 HANDLE file;
5336 ret = GetTempPathA(MAX_PATH, path);
5337 ok(ret, "Failed to get temporary file path.\n");
5338 filename = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
5339 ret = GetTempFileNameA(path, "d3d", 0, filename);
5340 ok(ret, "Failed to get filename.\n");
5341 file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
5342 ok(file != INVALID_HANDLE_VALUE, "Failed to open temporary file \"%s\".\n", filename);
5344 size = FIELD_OFFSET(BITMAPINFO, bmiColors[palettized ? 256 : 0]);
5346 memset(&file_header, 0, sizeof(file_header));
5347 file_header.bfType = 0x4d42; /* BM */
5348 file_header.bfOffBits = sizeof(file_header) + size;
5349 file_header.bfSize = file_header.bfOffBits + w * h * (bpp / 8);
5350 ret = WriteFile(file, &file_header, sizeof(file_header), &written, NULL);
5351 ok(ret && written == sizeof(file_header), "Failed to write file header.\n");
5353 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
5354 info->bmiHeader.biSize = sizeof(info->bmiHeader);
5355 info->bmiHeader.biBitCount = bpp;
5356 info->bmiHeader.biPlanes = 1;
5357 info->bmiHeader.biWidth = w;
5358 info->bmiHeader.biHeight = h;
5359 info->bmiHeader.biCompression = BI_RGB;
5360 if (palettized)
5362 for (i = 0; i < 256; ++i)
5364 info->bmiColors[i].rgbBlue = i;
5365 info->bmiColors[i].rgbGreen = i;
5366 info->bmiColors[i].rgbRed = i;
5369 ret = WriteFile(file, info, size, &written, NULL);
5370 ok(ret && written == size, "Failed to write bitmap info.\n");
5371 HeapFree(GetProcessHeap(), 0, info);
5373 size = w * h * (bpp / 8);
5374 buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
5375 for (i = 0, j = 0; i < size;)
5377 if (palettized)
5379 buffer[i++] = j++;
5380 j %= 256;
5382 else
5384 buffer[i++] = j % 251;
5385 buffer[i++] = j % 239;
5386 buffer[i++] = j++ % 247;
5389 ret = WriteFile(file, buffer, size, &written, NULL);
5390 ok(ret && written == size, "Failed to write bitmap data.\n");
5391 HeapFree(GetProcessHeap(), 0, buffer);
5393 CloseHandle(file);
5395 return filename;
5398 static void test_bitmap_data(unsigned int test_idx, const D3DRMIMAGE *img,
5399 BOOL upside_down, unsigned int w, unsigned int h, BOOL palettized)
5401 const unsigned char *data = img->buffer1;
5402 unsigned int i, j;
5404 ok(img->width == w, "Test %u: Got unexpected image width %u, expected %u.\n", test_idx, img->width, w);
5405 ok(img->height == h, "Test %u: Got unexpected image height %u, expected %u.\n", test_idx, img->height, h);
5406 ok(img->aspectx == 1, "Test %u: Got unexpected image aspectx %u.\n", test_idx, img->aspectx);
5407 ok(img->aspecty == 1, "Test %u: Got unexpected image aspecty %u.\n", test_idx, img->aspecty);
5408 ok(!img->buffer2, "Test %u: Got unexpected image buffer2 %p.\n", test_idx, img->buffer2);
5410 /* The image is palettized if the total number of colors used is <= 256. */
5411 if (w * h > 256 && !palettized)
5413 /* D3drm aligns the 24bpp texture to 4 bytes in the buffer, with one
5414 * byte padding from 24bpp texture. */
5415 ok(img->depth == 32, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
5416 ok(img->rgb == TRUE, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
5417 ok(img->bytes_per_line == w * 4, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5418 test_idx, img->bytes_per_line, w * 4);
5419 ok(img->red_mask == 0xff0000, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
5420 ok(img->green_mask == 0x00ff00, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
5421 ok(img->blue_mask == 0x0000ff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
5422 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
5423 ok(!img->palette_size, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
5424 ok(!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
5425 for (i = 0; i < h; ++i)
5427 for (j = 0; j < w; ++j)
5429 const unsigned char *ptr = &data[i * img->bytes_per_line + j * 4];
5430 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
5432 if (ptr[0] != idx % 251 || ptr[1] != idx % 239 || ptr[2] != idx % 247 || ptr[3] != 0xff)
5434 ok(0, "Test %u: Got unexpected color 0x%02x%02x%02x%02x at position %u, %u, "
5435 "expected 0x%02x%02x%02x%02x.\n", test_idx, ptr[0], ptr[1], ptr[2], ptr[3],
5436 j, i, idx % 251, idx % 239, idx % 247, 0xff);
5437 return;
5441 return;
5444 ok(img->depth == 8, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
5445 ok(!img->rgb, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
5446 ok(img->red_mask == 0xff, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
5447 ok(img->green_mask == 0xff, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
5448 ok(img->blue_mask == 0xff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
5449 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
5450 ok(!!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
5451 if (!palettized)
5453 /* In this case, bytes_per_line is aligned to the next multiple of
5454 * 4 from width. */
5455 ok(img->bytes_per_line == ((w + 3) & ~3), "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5456 test_idx, img->bytes_per_line, (w + 3) & ~3);
5457 ok(img->palette_size == w * h, "Test %u: Got unexpected palette size %u, expected %u.\n",
5458 test_idx, img->palette_size, w * h);
5459 for (i = 0; i < img->palette_size; ++i)
5461 unsigned int idx = upside_down ? (h - 1) * w - i + (i % w) * 2 : i;
5462 ok(img->palette[i].red == idx % 251
5463 && img->palette[i].green == idx % 239 && img->palette[i].blue == idx % 247,
5464 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
5465 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
5466 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
5467 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
5468 test_idx, i, img->palette[i].flags);
5470 for (i = 0; i < h; ++i)
5472 for (j = 0; j < w; ++j)
5474 if (data[i * img->bytes_per_line + j] != i * w + j)
5476 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
5477 test_idx, data[i * img->bytes_per_line + j], j, i, i * w + j);
5478 return;
5482 return;
5485 /* bytes_per_line is not always aligned by d3drm depending on the
5486 * format. */
5487 ok(img->bytes_per_line == w, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
5488 test_idx, img->bytes_per_line, w);
5489 ok(img->palette_size == 256, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
5490 for (i = 0; i < 256; ++i)
5492 ok(img->palette[i].red == i && img->palette[i].green == i && img->palette[i].blue == i,
5493 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
5494 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
5495 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
5496 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
5497 test_idx, i, img->palette[i].flags);
5499 for (i = 0; i < h; ++i)
5501 for (j = 0; j < w; ++j)
5503 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
5504 if (data[i * img->bytes_per_line + j] != idx % 256)
5506 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
5507 test_idx, data[i * img->bytes_per_line + j], j, i, idx % 256);
5508 return;
5514 static void test_load_texture(void)
5516 IDirect3DRMTexture3 *texture3;
5517 IDirect3DRMTexture2 *texture2;
5518 IDirect3DRMTexture *texture1;
5519 D3DRMIMAGE *d3drm_img;
5520 IDirect3DRM3 *d3drm3;
5521 IDirect3DRM2 *d3drm2;
5522 IDirect3DRM *d3drm1;
5523 char *filename;
5524 HRESULT hr;
5525 BOOL ret;
5526 int i;
5528 static const struct
5530 unsigned int w;
5531 unsigned int h;
5532 BOOL palettized;
5534 tests[] =
5536 {100, 100, TRUE },
5537 {99, 100, TRUE },
5538 {100, 100, FALSE},
5539 {99, 100, FALSE},
5540 {3, 39, FALSE},
5543 hr = Direct3DRMCreate(&d3drm1);
5544 ok(hr == D3DRM_OK, "Failed to create IDirect3DRM object, hr %#x.\n", hr);
5545 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5546 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM2 interface, hr %#x.\n", hr);
5547 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5548 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM3 interface, hr %#x.\n", hr);
5550 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
5552 filename = create_bitmap(tests[i].w, tests[i].h, tests[i].palettized);
5554 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
5555 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5556 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
5557 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5558 if (d3drm_img)
5559 test_bitmap_data(i * 4, d3drm_img, FALSE, tests[i].w, tests[i].h, tests[i].palettized);
5560 IDirect3DRMTexture_Release(texture1);
5562 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
5563 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5564 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
5565 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5566 if (d3drm_img)
5567 test_bitmap_data(i * 4 + 1, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5568 IDirect3DRMTexture2_Release(texture2);
5570 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
5571 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
5572 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
5573 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5574 if (d3drm_img)
5575 test_bitmap_data(i * 4 + 2, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5576 /* Test whether querying a version 1 texture from version 3 causes a
5577 * change in the loading behavior. */
5578 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IDirect3DRMTexture, (void **)&texture1);
5579 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMTexture interface, hr %#x.\n", hr);
5580 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
5581 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
5582 if (d3drm_img)
5583 test_bitmap_data(i * 4 + 3, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
5584 IDirect3DRMTexture_Release(texture1);
5585 IDirect3DRMTexture3_Release(texture3);
5587 ret = DeleteFileA(filename);
5588 ok(ret, "Test %u: Failed to delete bitmap \"%s\".\n", i, filename);
5589 HeapFree(GetProcessHeap(), 0, filename);
5592 IDirect3DRM3_Release(d3drm3);
5593 IDirect3DRM2_Release(d3drm2);
5594 IDirect3DRM_Release(d3drm1);
5597 static void test_texture_qi(void)
5599 static const struct qi_test tests[] =
5601 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5602 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5603 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5604 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5605 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5606 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5607 { &IID_IDirect3DRMWinDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5608 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5609 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5610 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5611 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5612 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5613 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5614 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5615 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5616 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5617 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5618 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5619 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5620 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5621 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5622 { &IID_IDirect3DRMTexture, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
5623 { &IID_IDirect3DRMTexture2, &IID_IUnknown, &IID_IDirect3DRMTexture2, S_OK },
5624 { &IID_IDirect3DRMTexture3, &IID_IUnknown, &IID_IDirect3DRMTexture3, S_OK },
5625 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5626 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5627 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5628 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5629 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5630 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5631 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5632 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5633 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5634 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5635 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5636 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5637 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5638 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5639 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5640 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5641 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5642 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5643 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5644 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5645 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5646 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5647 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5648 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5649 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5650 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5651 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5652 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5653 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5654 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5655 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5656 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5657 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5658 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5659 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5660 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5661 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5662 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5663 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5664 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5665 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5666 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5667 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5668 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
5670 HRESULT hr;
5671 IDirect3DRM *d3drm1;
5672 IDirect3DRM2 *d3drm2;
5673 IDirect3DRM3 *d3drm3;
5674 IDirect3DRMTexture *texture1;
5675 IDirect3DRMTexture2 *texture2;
5676 IDirect3DRMTexture3 *texture3;
5677 IUnknown *unknown;
5678 char *filename;
5679 BOOL check;
5681 hr = Direct3DRMCreate(&d3drm1);
5682 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x)\n", hr);
5683 filename = create_bitmap(1, 1, TRUE);
5684 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
5685 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5686 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
5687 hr = IDirect3DRMTexture_QueryInterface(texture1, &IID_IUnknown, (void **)&unknown);
5688 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture (hr = %#x)\n", hr);
5689 IDirect3DRMTexture_Release(texture1);
5690 test_qi("texture1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5691 IUnknown_Release(unknown);
5693 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5694 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
5695 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
5696 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5697 hr = IDirect3DRMTexture2_QueryInterface(texture2, &IID_IUnknown, (void **)&unknown);
5698 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture2 (hr = %#x)\n", hr);
5699 IDirect3DRMTexture2_Release(texture2);
5700 test_qi("texture2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5701 IUnknown_Release(unknown);
5703 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5704 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
5705 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
5706 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
5707 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
5708 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IUnknown, (void **)&unknown);
5709 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture3 (hr = %#x)\n", hr);
5710 IDirect3DRMTexture3_Release(texture3);
5711 test_qi("texture3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5712 IUnknown_Release(unknown);
5714 IDirect3DRM3_Release(d3drm3);
5715 IDirect3DRM2_Release(d3drm2);
5716 IDirect3DRM_Release(d3drm1);
5717 check = DeleteFileA(filename);
5718 ok(check, "Cannot delete image stored in %s (error = %d).\n", filename, GetLastError());
5719 HeapFree(GetProcessHeap(), 0, filename);
5722 static void test_viewport_qi(void)
5724 IDirect3DRM *d3drm1;
5725 IDirect3DRM2 *d3drm2;
5726 IDirect3DRM3 *d3drm3;
5727 IDirect3DRMFrame *frame1, *camera1;
5728 IDirect3DRMFrame3 *frame3, *camera3;
5729 IDirect3DRMDevice *device1;
5730 IDirect3DRMDevice3 *device3;
5731 IDirectDrawClipper *clipper;
5732 IDirect3DRMViewport *viewport1;
5733 IDirect3DRMViewport2 *viewport2;
5734 IUnknown *unknown;
5735 GUID driver = IID_IDirect3DRGBDevice;
5736 HRESULT hr;
5738 static const struct qi_test tests[] =
5740 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5741 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5742 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5743 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5744 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5745 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5746 { &IID_IDirect3DRMWinDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5747 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMViewport, S_OK },
5748 { &IID_IDirect3DRMViewport, &IID_IUnknown, &IID_IDirect3DRMViewport, S_OK },
5749 { &IID_IDirect3DRMViewport2, &IID_IUnknown, &IID_IDirect3DRMViewport2, S_OK },
5750 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5751 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5752 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5753 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5754 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5755 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5756 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5757 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5758 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5759 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5760 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5761 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5762 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5763 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5764 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5765 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5766 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5767 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5768 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5769 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5770 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5771 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5772 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5773 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5774 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5775 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5776 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5777 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5778 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5779 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5780 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5781 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5782 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5783 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5784 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5785 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5786 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5787 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5788 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5789 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5790 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5791 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5792 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5793 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5794 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5795 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5796 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5797 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5798 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5799 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5800 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5801 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5802 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5803 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5804 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5805 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5806 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
5807 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
5810 hr = DirectDrawCreateClipper(0, &clipper, NULL);
5811 ok(SUCCEEDED(hr), "Cannot get IDirectDrawClipper interface (hr = %#x).\n", hr);
5813 hr = Direct3DRMCreate(&d3drm1);
5814 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
5816 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 640, 480, &device1);
5817 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %#x).\n", hr);
5818 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
5819 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
5820 hr = IDirect3DRM_CreateFrame(d3drm1, frame1, &camera1);
5821 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
5822 hr = IDirect3DRM_CreateViewport(d3drm1, device1, camera1, 0, 0, 640, 480, &viewport1);
5823 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
5824 hr = IDirect3DRMViewport_QueryInterface(viewport1, &IID_IUnknown, (void **)&unknown);
5825 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5826 IDirect3DRMViewport_Release(viewport1);
5827 test_qi("viewport1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5828 IUnknown_Release(unknown);
5830 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
5831 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
5832 hr = IDirect3DRM2_CreateViewport(d3drm2, device1, camera1, 0, 0, 640, 480, &viewport1);
5833 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport interface (hr = %#x)\n", hr);
5834 hr = IDirect3DRMViewport_QueryInterface(viewport1, &IID_IUnknown, (void **)&unknown);
5835 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5836 IDirect3DRMViewport_Release(viewport1);
5837 test_qi("viewport1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5838 IUnknown_Release(unknown);
5839 IDirect3DRMDevice_Release(device1);
5840 IDirect3DRMFrame_Release(camera1);
5841 IDirect3DRMFrame_Release(frame1);
5843 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
5844 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
5845 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 640, 480, &device3);
5846 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %#x).\n", hr);
5847 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
5848 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
5849 hr = IDirect3DRM3_CreateFrame(d3drm3, frame3, &camera3);
5850 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
5851 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, 640, 480, &viewport2);
5852 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
5853 hr = IDirect3DRMViewport2_QueryInterface(viewport2, &IID_IUnknown, (void **)&unknown);
5854 ok(SUCCEEDED(hr), "Cannot get IUnknown interface (hr = %#x).\n", hr);
5855 IDirect3DRMViewport_Release(viewport2);
5856 test_qi("viewport2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
5857 IUnknown_Release(unknown);
5858 IDirect3DRMDevice3_Release(device3);
5859 IDirect3DRMFrame3_Release(camera3);
5860 IDirect3DRMFrame3_Release(frame3);
5862 IDirectDrawClipper_Release(clipper);
5863 IDirect3DRM3_Release(d3drm3);
5864 IDirect3DRM2_Release(d3drm2);
5865 IDirect3DRM_Release(d3drm1);
5868 static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
5870 RECT rect = { x, y, x + 1, y + 1 };
5871 DDSURFACEDESC surface_desc;
5872 D3DCOLOR color;
5873 HRESULT hr;
5875 memset(&surface_desc, 0, sizeof(surface_desc));
5876 surface_desc.dwSize = sizeof(surface_desc);
5878 hr = IDirectDrawSurface_Lock(surface, &rect, &surface_desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL);
5879 ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
5880 if (FAILED(hr))
5881 return 0xdeadbeef;
5883 color = *((DWORD *)surface_desc.lpSurface) & 0x00ffffff;
5885 hr = IDirectDrawSurface_Unlock(surface, NULL);
5886 ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
5888 return color;
5891 static IDirect3DDevice2 *create_device2_without_ds(IDirectDraw2 *ddraw, HWND window)
5893 IDirectDrawSurface *surface;
5894 IDirect3DDevice2 *device = NULL;
5895 DDSURFACEDESC surface_desc;
5896 IDirect3D2 *d3d;
5897 HRESULT hr;
5898 RECT rc;
5900 GetClientRect(window, &rc);
5901 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
5902 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
5904 memset(&surface_desc, 0, sizeof(surface_desc));
5905 surface_desc.dwSize = sizeof(surface_desc);
5906 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
5907 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
5908 surface_desc.dwWidth = rc.right;
5909 surface_desc.dwHeight = rc.bottom;
5911 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
5912 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
5914 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
5915 if (FAILED(hr))
5917 IDirectDrawSurface_Release(surface);
5918 return NULL;
5921 IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device);
5923 IDirect3D2_Release(d3d);
5924 IDirectDrawSurface_Release(surface);
5925 return device;
5928 static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
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 c1 >>= 8; c2 >>= 8;
5936 if ((c1 & 0xff) - (c2 & 0xff) > max_diff) return FALSE;
5937 return TRUE;
5940 static void clear_depth_surface(IDirectDrawSurface *surface, DWORD value)
5942 HRESULT hr;
5943 DDBLTFX fx;
5945 memset(&fx, 0, sizeof(fx));
5946 fx.dwSize = sizeof(fx);
5947 U5(fx).dwFillDepth = value;
5949 hr = IDirectDrawSurface_Blt(surface, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
5950 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
5953 static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex_count, UINT offset, UINT len)
5955 D3DEXECUTEDATA exec_data;
5956 HRESULT hr;
5958 memset(&exec_data, 0, sizeof(exec_data));
5959 exec_data.dwSize = sizeof(exec_data);
5960 exec_data.dwVertexCount = vertex_count;
5961 exec_data.dwInstructionOffset = offset;
5962 exec_data.dwInstructionLength = len;
5963 hr = IDirect3DExecuteBuffer_SetExecuteData(execute_buffer, &exec_data);
5964 ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
5967 static void emit_set_ts(void **ptr, D3DTRANSFORMSTATETYPE state, DWORD value)
5969 D3DINSTRUCTION *inst = *ptr;
5970 D3DSTATE *ts = (D3DSTATE *)(inst + 1);
5972 inst->bOpcode = D3DOP_STATETRANSFORM;
5973 inst->bSize = sizeof(*ts);
5974 inst->wCount = 1;
5976 U1(*ts).dtstTransformStateType = state;
5977 U2(*ts).dwArg[0] = value;
5979 *ptr = ts + 1;
5982 static void emit_set_rs(void **ptr, D3DRENDERSTATETYPE state, DWORD value)
5984 D3DINSTRUCTION *inst = *ptr;
5985 D3DSTATE *rs = (D3DSTATE *)(inst + 1);
5987 inst->bOpcode = D3DOP_STATERENDER;
5988 inst->bSize = sizeof(*rs);
5989 inst->wCount = 1;
5991 U1(*rs).drstRenderStateType = state;
5992 U2(*rs).dwArg[0] = value;
5994 *ptr = rs + 1;
5997 static void emit_process_vertices(void **ptr, DWORD flags, WORD base_idx, DWORD vertex_count)
5999 D3DINSTRUCTION *inst = *ptr;
6000 D3DPROCESSVERTICES *pv = (D3DPROCESSVERTICES *)(inst + 1);
6002 inst->bOpcode = D3DOP_PROCESSVERTICES;
6003 inst->bSize = sizeof(*pv);
6004 inst->wCount = 1;
6006 pv->dwFlags = flags;
6007 pv->wStart = base_idx;
6008 pv->wDest = 0;
6009 pv->dwCount = vertex_count;
6010 pv->dwReserved = 0;
6012 *ptr = pv + 1;
6015 static void emit_tquad(void **ptr, WORD base_idx)
6017 D3DINSTRUCTION *inst = *ptr;
6018 D3DTRIANGLE *tri = (D3DTRIANGLE *)(inst + 1);
6020 inst->bOpcode = D3DOP_TRIANGLE;
6021 inst->bSize = sizeof(*tri);
6022 inst->wCount = 2;
6024 U1(*tri).v1 = base_idx;
6025 U2(*tri).v2 = base_idx + 1;
6026 U3(*tri).v3 = base_idx + 2;
6027 tri->wFlags = D3DTRIFLAG_START;
6028 ++tri;
6030 U1(*tri).v1 = base_idx + 2;
6031 U2(*tri).v2 = base_idx + 1;
6032 U3(*tri).v3 = base_idx + 3;
6033 tri->wFlags = D3DTRIFLAG_ODD;
6034 ++tri;
6036 *ptr = tri;
6039 static void emit_end(void **ptr)
6041 D3DINSTRUCTION *inst = *ptr;
6043 inst->bOpcode = D3DOP_EXIT;
6044 inst->bSize = 0;
6045 inst->wCount = 0;
6047 *ptr = inst + 1;
6050 static void d3d_draw_quad1(IDirect3DDevice *device, IDirect3DViewport *viewport)
6052 IDirect3DExecuteBuffer *execute_buffer;
6053 D3DEXECUTEBUFFERDESC exec_desc;
6054 HRESULT hr;
6055 void *ptr;
6056 UINT inst_length;
6057 D3DMATRIXHANDLE world_handle, view_handle, proj_handle;
6058 static D3DMATRIX mat =
6060 1.0f, 0.0f, 0.0f, 0.0f,
6061 0.0f, 1.0f, 0.0f, 0.0f,
6062 0.0f, 0.0f, 1.0f, 0.0f,
6063 0.0f, 0.0f, 0.0f, 1.0f,
6065 static const D3DLVERTEX quad_strip[] =
6067 {{-1.0f}, {-1.0f}, {0.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6068 {{-1.0f}, { 1.0f}, {0.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6069 {{ 1.0f}, {-1.0f}, {1.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6070 {{ 1.0f}, { 1.0f}, {1.00f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6073 hr = IDirect3DDevice_CreateMatrix(device, &world_handle);
6074 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6075 hr = IDirect3DDevice_SetMatrix(device, world_handle, &mat);
6076 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6077 hr = IDirect3DDevice_CreateMatrix(device, &view_handle);
6078 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6079 hr = IDirect3DDevice_SetMatrix(device, view_handle, &mat);
6080 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6081 hr = IDirect3DDevice_CreateMatrix(device, &proj_handle);
6082 ok(hr == D3D_OK, "Creating a matrix object failed, hr %#x.\n", hr);
6083 hr = IDirect3DDevice_SetMatrix(device, proj_handle, &mat);
6084 ok(hr == D3D_OK, "Setting a matrix object failed, hr %#x.\n", hr);
6086 memset(&exec_desc, 0, sizeof(exec_desc));
6087 exec_desc.dwSize = sizeof(exec_desc);
6088 exec_desc.dwFlags = D3DDEB_BUFSIZE | D3DDEB_CAPS;
6089 exec_desc.dwBufferSize = 1024;
6090 exec_desc.dwCaps = D3DDEBCAPS_SYSTEMMEMORY;
6092 hr = IDirect3DDevice_CreateExecuteBuffer(device, &exec_desc, &execute_buffer, NULL);
6093 ok(SUCCEEDED(hr), "Failed to create execute buffer, hr %#x.\n", hr);
6095 hr = IDirect3DExecuteBuffer_Lock(execute_buffer, &exec_desc);
6096 ok(SUCCEEDED(hr), "Failed to lock execute buffer, hr %#x.\n", hr);
6098 memcpy(exec_desc.lpData, quad_strip, sizeof(quad_strip));
6099 ptr = ((BYTE *)exec_desc.lpData) + sizeof(quad_strip);
6100 emit_set_ts(&ptr, D3DTRANSFORMSTATE_WORLD, world_handle);
6101 emit_set_ts(&ptr, D3DTRANSFORMSTATE_VIEW, view_handle);
6102 emit_set_ts(&ptr, D3DTRANSFORMSTATE_PROJECTION, proj_handle);
6103 emit_set_rs(&ptr, D3DRENDERSTATE_CLIPPING, FALSE);
6104 emit_set_rs(&ptr, D3DRENDERSTATE_ZENABLE, TRUE);
6105 emit_set_rs(&ptr, D3DRENDERSTATE_FOGENABLE, FALSE);
6106 emit_set_rs(&ptr, D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
6107 emit_set_rs(&ptr, D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT);
6109 emit_process_vertices(&ptr, D3DPROCESSVERTICES_TRANSFORM, 0, 4);
6110 emit_tquad(&ptr, 0);
6112 emit_end(&ptr);
6113 inst_length = (BYTE *)ptr - (BYTE *)exec_desc.lpData;
6114 inst_length -= sizeof(quad_strip);
6116 hr = IDirect3DExecuteBuffer_Unlock(execute_buffer);
6117 ok(SUCCEEDED(hr), "Failed to unlock execute buffer, hr %#x.\n", hr);
6119 hr = IDirect3DDevice_BeginScene(device);
6120 set_execute_data(execute_buffer, 4, sizeof(quad_strip), inst_length);
6121 hr = IDirect3DDevice_Execute(device, execute_buffer, viewport, D3DEXECUTE_CLIPPED);
6122 ok(SUCCEEDED(hr), "Failed to execute exec buffer, hr %#x.\n", hr);
6123 hr = IDirect3DDevice_EndScene(device);
6124 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6126 IDirect3DExecuteBuffer_Release(execute_buffer);
6129 static void test_viewport_clear1(void)
6131 DDSCAPS caps = { DDSCAPS_ZBUFFER };
6132 IDirectDraw *ddraw;
6133 IDirectDrawClipper *clipper;
6134 IDirect3DRM *d3drm1;
6135 IDirect3DRMFrame *frame1, *camera1;
6136 IDirect3DRMDevice *device1;
6137 IDirect3DViewport *d3d_viewport;
6138 IDirect3DRMViewport *viewport1;
6139 IDirect3DDevice *d3d_device1;
6140 IDirectDrawSurface *surface, *ds, *d3drm_ds;
6141 HWND window;
6142 GUID driver = IID_IDirect3DRGBDevice;
6143 HRESULT hr;
6144 D3DCOLOR ret_color;
6145 RECT rc;
6147 window = create_window();
6148 GetClientRect(window, &rc);
6150 hr = DirectDrawCreate(NULL, &ddraw, NULL);
6151 ok(SUCCEEDED(hr), "Cannot create IDirectDraw interface (hr = %#x).\n", hr);
6153 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6154 ok(SUCCEEDED(hr), "Failed to set cooperative level (hr = %#x).\n", hr);
6156 hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
6157 ok(SUCCEEDED(hr), "Cannot create clipper (hr = %#x).\n", hr);
6159 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
6160 ok(SUCCEEDED(hr), "Cannot set HWnd to Clipper (hr = %#x)\n", hr);
6162 hr = Direct3DRMCreate(&d3drm1);
6163 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
6165 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
6166 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %#x)\n", hr);
6168 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
6169 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
6170 hr = IDirect3DRM_CreateFrame(d3drm1, frame1, &camera1);
6171 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr);
6173 hr = IDirect3DRM_CreateViewport(d3drm1, device1, camera1, 0, 0, rc.right,
6174 rc.bottom, &viewport1);
6175 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6177 /* Fetch immediate mode device and viewport */
6178 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3d_device1);
6179 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice interface (hr = %#x).\n", hr);
6180 hr = IDirect3DRMViewport_GetDirect3DViewport(viewport1, &d3d_viewport);
6181 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
6183 hr = IDirect3DDevice_QueryInterface(d3d_device1, &IID_IDirectDrawSurface, (void **)&surface);
6184 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6186 ret_color = get_surface_color(surface, 320, 240);
6187 ok(compare_color(ret_color, 0, 1), "Got unexpected color 0x%08x.\n", ret_color);
6189 /* Clear uses the scene frame's background color. */
6190 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(frame1, 1.0f, 1.0f, 1.0f);
6191 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6192 ret_color = IDirect3DRMFrame_GetSceneBackground(frame1);
6193 ok(ret_color == 0xffffffff, "Expected scene color returned == 0xffffffff, got %#x.\n", ret_color);
6194 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(camera1, 0.0f, 1.0f, 0.0f);
6195 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6196 ret_color = IDirect3DRMFrame_GetSceneBackground(camera1);
6197 ok(ret_color == 0xff00ff00, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6199 hr = IDirect3DRMViewport_Clear(viewport1);
6200 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6201 ret_color = get_surface_color(surface, 320, 240);
6202 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6204 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(frame1, 0.0f, 0.0f, 1.0f);
6205 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6206 ret_color = IDirect3DRMFrame_GetSceneBackground(frame1);
6207 ok(ret_color == 0xff0000ff, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6209 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6210 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6211 hr = IDirect3DRMViewport_Clear(viewport1);
6212 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6213 ret_color = get_surface_color(surface, 100, 200);
6214 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6216 d3d_draw_quad1(d3d_device1, d3d_viewport);
6218 ret_color = get_surface_color(surface, 100, 200);
6219 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6221 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
6222 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
6224 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6225 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6226 hr = IDirect3DRMViewport_Clear(viewport1);
6227 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6228 ret_color = get_surface_color(surface, 100, 200);
6229 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6231 /* Fill the depth surface with a value lower than the quad's depth value. */
6232 clear_depth_surface(ds, 0x7fff);
6234 /* Depth test passes here */
6235 d3d_draw_quad1(d3d_device1, d3d_viewport);
6236 ret_color = get_surface_color(surface, 100, 200);
6237 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6238 /* Depth test fails here */
6239 ret_color = get_surface_color(surface, 500, 400);
6240 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6242 /* Check what happens if we release the depth surface that d3drm created, and clear the viewport */
6243 hr = IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
6244 ok(SUCCEEDED(hr), "Cannot delete attached surface (hr = %#x).\n", hr);
6245 d3drm_ds = (IDirectDrawSurface *)0xdeadbeef;
6246 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
6247 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %#x.\n", hr);
6248 ok(d3drm_ds == NULL, "Expected NULL z-surface, got %p.\n", d3drm_ds);
6250 clear_depth_surface(ds, 0x7fff);
6251 hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom);
6252 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6253 hr = IDirect3DRMViewport_Clear(viewport1);
6254 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6256 ret_color = get_surface_color(surface, 100, 200);
6257 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6259 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
6260 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
6261 IDirectDrawSurface_Release(ds);
6263 d3d_draw_quad1(d3d_device1, d3d_viewport);
6265 ret_color = get_surface_color(surface, 100, 200);
6266 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6267 ret_color = get_surface_color(surface, 500, 400);
6268 ok(compare_color(ret_color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6270 IDirect3DViewport_Release(d3d_viewport);
6271 IDirectDrawSurface_Release(surface);
6272 IDirect3DDevice_Release(d3d_device1);
6273 IDirect3DRMViewport_Release(viewport1);
6274 IDirect3DRMFrame_Release(frame1);
6275 IDirect3DRMFrame_Release(camera1);
6276 IDirect3DRMDevice_Release(device1);
6277 IDirect3DRM_Release(d3drm1);
6278 IDirectDrawClipper_Release(clipper);
6279 IDirectDraw_Release(ddraw);
6280 DestroyWindow(window);
6283 static void draw_quad2(IDirect3DDevice2 *device, IDirect3DViewport *viewport)
6285 static D3DLVERTEX tquad[] =
6287 {{-1.0f}, {-1.0f}, {0.0f}, 0, {0xffbada55}, {0}, {0.0f}, {0.0f}},
6288 {{-1.0f}, { 1.0f}, {0.0f}, 0, {0xffbada55}, {0}, {0.0f}, {1.0f}},
6289 {{ 1.0f}, {-1.0f}, {1.0f}, 0, {0xffbada55}, {0}, {1.0f}, {0.0f}},
6290 {{ 1.0f}, { 1.0f}, {1.0f}, 0, {0xffbada55}, {0}, {1.0f}, {1.0f}},
6292 static D3DMATRIX mat =
6294 1.0f, 0.0f, 0.0f, 0.0f,
6295 0.0f, 1.0f, 0.0f, 0.0f,
6296 0.0f, 0.0f, 1.0f, 0.0f,
6297 0.0f, 0.0f, 0.0f, 1.0f,
6299 IDirect3DViewport2 *viewport2;
6300 HRESULT hr;
6302 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_WORLD, &mat);
6303 ok(SUCCEEDED(hr), "Failed to set world transform, hr %#x.\n", hr);
6304 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_VIEW, &mat);
6305 ok(SUCCEEDED(hr), "Failed to set view transform, hr %#x.\n", hr);
6306 hr = IDirect3DDevice2_SetTransform(device, D3DTRANSFORMSTATE_PROJECTION, &mat);
6307 ok(SUCCEEDED(hr), "Failed to set projection transform, hr %#x.\n", hr);
6309 hr = IDirect3DViewport_QueryInterface(viewport, &IID_IDirect3DViewport2, (void **)&viewport2);
6310 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport2 interface (hr = %#x).\n", hr);
6311 hr = IDirect3DDevice2_SetCurrentViewport(device, viewport2);
6312 ok(SUCCEEDED(hr), "Failed to activate the viewport, hr %#x.\n", hr);
6313 IDirect3DViewport2_Release(viewport2);
6315 hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
6316 ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
6317 hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
6318 ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
6320 hr = IDirect3DDevice2_BeginScene(device);
6321 ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
6322 hr = IDirect3DDevice2_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DVT_LVERTEX, tquad, 4, 0);
6323 ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
6324 hr = IDirect3DDevice2_EndScene(device);
6325 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6328 static void test_viewport_clear2(void)
6330 DDSCAPS caps = { DDSCAPS_ZBUFFER };
6331 IDirect3D2 *d3d2;
6332 IDirectDraw *ddraw1;
6333 IDirectDraw2 *ddraw2;
6334 IDirectDrawClipper *clipper;
6335 IDirect3DRM *d3drm1;
6336 IDirect3DRM3 *d3drm3;
6337 IDirect3DRMFrame3 *frame3, *camera3;
6338 IDirect3DRMDevice3 *device3;
6339 IDirect3DViewport *d3d_viewport;
6340 IDirect3DRMViewport2 *viewport2;
6341 IDirect3DDevice2 *d3d_device2;
6342 IDirectDrawSurface *surface, *ds, *d3drm_ds;
6343 HWND window;
6344 GUID driver = IID_IDirect3DRGBDevice;
6345 HRESULT hr;
6346 D3DCOLOR ret_color;
6347 RECT rc;
6349 window = create_window();
6350 GetClientRect(window, &rc);
6352 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
6353 ok(SUCCEEDED(hr), "Cannot create IDirectDraw interface (hr = %#x).\n", hr);
6355 hr = IDirectDraw_SetCooperativeLevel(ddraw1, window, DDSCL_NORMAL);
6356 ok(SUCCEEDED(hr), "Failed to set cooperative level (hr = %#x).\n", hr);
6358 hr = IDirectDraw_CreateClipper(ddraw1, 0, &clipper, NULL);
6359 ok(SUCCEEDED(hr), "Cannot create clipper (hr = %#x).\n", hr);
6361 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
6362 ok(SUCCEEDED(hr), "Cannot set HWnd to Clipper (hr = %#x)\n", hr);
6364 hr = Direct3DRMCreate(&d3drm1);
6365 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
6367 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
6368 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
6370 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
6371 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice3 interface (hr = %#x)\n", hr);
6373 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
6374 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
6375 hr = IDirect3DRM3_CreateFrame(d3drm3, frame3, &camera3);
6376 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr);
6378 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, rc.right,
6379 rc.bottom, &viewport2);
6380 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6382 /* Fetch immediate mode device in order to access render target and test its color. */
6383 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3d_device2);
6384 ok(SUCCEEDED(hr), "Cannot get IDirect3DDevice2 interface (hr = %#x).\n", hr);
6386 hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
6387 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6389 ret_color = get_surface_color(surface, 320, 240);
6390 ok(compare_color(ret_color, 0, 1), "Got unexpected color 0x%08x.\n", ret_color);
6392 /* Clear uses the scene frame's background color. */
6393 hr = IDirect3DRMFrame3_SetSceneBackgroundRGB(frame3, 1.0f, 1.0f, 1.0f);
6394 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6395 ret_color = IDirect3DRMFrame3_GetSceneBackground(frame3);
6396 ok(ret_color == 0xffffffff, "Expected scene color returned == 0xffffffff, got %#x.\n", ret_color);
6397 hr = IDirect3DRMFrame3_SetSceneBackgroundRGB(camera3, 0.0f, 1.0f, 0.0f);
6398 ok(SUCCEEDED(hr), "Cannot set scene background RGB (hr = %#x)\n", hr);
6399 ret_color = IDirect3DRMFrame3_GetSceneBackground(camera3);
6400 ok(ret_color == 0xff00ff00, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
6402 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6403 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6404 ret_color = get_surface_color(surface, 320, 240);
6405 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6407 hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport);
6408 ok(SUCCEEDED(hr), "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr);
6410 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6411 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6413 /* d3drm seems to be calling BeginScene when Clear is called. */
6414 hr = IDirect3DDevice2_BeginScene(d3d_device2);
6415 todo_wine ok(hr == D3DERR_SCENE_IN_SCENE, "Expected hr == D3DERR_SCENE_IN_SCENE, got %#x.\n", hr);
6416 hr = IDirect3DDevice2_EndScene(d3d_device2);
6417 ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
6419 ret_color = get_surface_color(surface, 320, 240);
6420 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6422 /* We're using d3d to draw using IDirect3DDevice2 created from d3drm. */
6423 draw_quad2(d3d_device2, d3d_viewport);
6424 ret_color = get_surface_color(surface, 320, 240);
6425 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6427 /* Without calling Configure, Clear doesn't work. */
6428 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6429 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6430 ret_color = get_surface_color(surface, 320, 240);
6431 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6433 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6434 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6435 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6436 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6438 ret_color = get_surface_color(surface, 320, 240);
6439 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6441 /* Fetch attached depth surface and see if viewport clears it if it's detached from the render target. */
6442 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
6443 ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
6445 clear_depth_surface(ds, 0x39);
6446 draw_quad2(d3d_device2, d3d_viewport);
6448 ret_color = get_surface_color(surface, 320, 240);
6449 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6451 hr = IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds);
6452 ok(SUCCEEDED(hr), "Cannot delete attached surface (hr = %#x).\n", hr);
6453 d3drm_ds = (IDirectDrawSurface *)0xdeadbeef;
6454 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
6455 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %#x.\n", hr);
6456 ok(d3drm_ds == NULL, "Expected NULL z-surface, got %p.\n", d3drm_ds);
6458 clear_depth_surface(ds, 0x7fff);
6460 /* This version of Clear still clears the depth surface even if it's deleted from the render target. */
6461 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6462 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6463 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6464 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6466 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
6467 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
6468 ret_color = get_surface_color(surface, 320, 240);
6469 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6471 draw_quad2(d3d_device2, d3d_viewport);
6472 ret_color = get_surface_color(surface, 100, 200);
6473 ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6474 ret_color = get_surface_color(surface, 500, 400);
6475 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6477 /* Clear with no flags */
6478 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6479 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6480 hr = IDirect3DRMViewport2_Clear(viewport2, 0);
6481 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6482 ret_color = get_surface_color(surface, 320, 240);
6483 todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
6485 hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom);
6486 todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr);
6487 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6488 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6489 ret_color = get_surface_color(surface, 320, 240);
6490 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6492 IDirect3DViewport_Release(d3d_viewport);
6493 IDirectDrawSurface_Release(surface);
6494 IDirectDrawSurface_Release(ds);
6495 IDirect3DDevice2_Release(d3d_device2);
6496 IDirect3DRMViewport2_Release(viewport2);
6497 IDirect3DRMDevice3_Release(device3);
6499 /* Create device without depth surface attached */
6500 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
6501 ok(SUCCEEDED(hr), "Cannot get IDirectDraw2 interface (hr = %#x).\n", hr);
6502 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
6503 ok(SUCCEEDED(hr), "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
6504 d3d_device2 = create_device2_without_ds(ddraw2, window);
6505 if (!d3d_device2)
6506 goto cleanup;
6508 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3d_device2, &device3);
6509 ok(SUCCEEDED(hr), "Failed to create IDirect3DRMDevice interface (hr = %#x)\n", hr);
6510 hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, rc.right,
6511 rc.bottom, &viewport2);
6512 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr);
6513 hr = IDirect3DDevice2_GetRenderTarget(d3d_device2, &surface);
6514 ok(SUCCEEDED(hr), "Cannot get surface to the render target (hr = %#x).\n", hr);
6516 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL);
6517 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6518 ret_color = get_surface_color(surface, 320, 240);
6519 ok(compare_color(ret_color, 0x00ffffff, 1), "Got unexpected color 0x%08x.\n", ret_color);
6521 hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ZBUFFER);
6522 ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
6524 IDirectDrawSurface_Release(surface);
6525 IDirect3DRMViewport2_Release(viewport2);
6526 IDirect3DRMDevice3_Release(device3);
6527 IDirect3DDevice2_Release(d3d_device2);
6529 cleanup:
6530 IDirect3DRMFrame3_Release(camera3);
6531 IDirect3DRMFrame3_Release(frame3);
6532 IDirect3DRM3_Release(d3drm3);
6533 IDirect3DRM_Release(d3drm1);
6534 IDirectDrawClipper_Release(clipper);
6535 IDirect3D2_Release(d3d2);
6536 IDirectDraw2_Release(ddraw2);
6537 IDirectDraw_Release(ddraw1);
6538 DestroyWindow(window);
6541 static void test_create_texture_from_surface(void)
6543 D3DRMIMAGE testimg =
6545 0, 0, 0, 0, 0,
6546 TRUE, 0, (void *)0xcafebabe, NULL,
6547 0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
6549 IDirectDrawSurface *surface = NULL, *surface2 = NULL, *ds = NULL;
6550 IDirect3DRMTexture *texture1;
6551 IDirect3DRMTexture2 *texture2;
6552 IDirect3DRMTexture3 *texture3;
6553 IDirectDraw *ddraw = NULL;
6554 IDirect3DRM *d3drm1 = NULL;
6555 IDirect3DRM2 *d3drm2 = NULL;
6556 IDirect3DRM3 *d3drm3 = NULL;
6557 ULONG ref1, ref2, ref3;
6558 D3DRMIMAGE *image;
6559 DDSURFACEDESC desc;
6560 HWND window;
6561 HRESULT hr;
6562 RECT rc;
6564 hr = DirectDrawCreate(NULL, &ddraw, NULL);
6565 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
6567 window = create_window();
6568 GetClientRect(window, &rc);
6570 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
6571 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
6573 hr = Direct3DRMCreate(&d3drm1);
6574 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
6576 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
6577 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
6579 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
6580 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
6582 /* Create a surface and use it to create a texture. */
6583 memset(&desc, 0, sizeof(desc));
6584 desc.dwSize = sizeof(desc);
6585 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
6586 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
6587 desc.dwWidth = rc.right;
6588 desc.dwHeight = rc.bottom;
6590 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
6591 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6593 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface2, NULL);
6594 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
6596 /* Test NULL params */
6597 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
6598 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, NULL, &texture1);
6599 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6600 ok(!texture1, "Expected texture returned == NULL, got %p.\n", texture1);
6602 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, NULL, NULL);
6603 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6605 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
6606 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, NULL, &texture2);
6607 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6608 ok(!texture2, "Expected texture returned == NULL, got %p.\n", texture2);
6610 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, NULL, NULL);
6611 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6613 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
6614 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, NULL, &texture3);
6615 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6616 ok(!texture3, "Expected texture returned == NULL, got %p.\n", texture3);
6618 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, NULL, NULL);
6619 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6621 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6622 hr = IDirect3DRM_CreateTextureFromSurface(d3drm1, surface, &texture1);
6623 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6625 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6626 image = IDirect3DRMTexture_GetImage(texture1);
6627 ok(image == NULL, "Unexpected image, %p.\n", image);
6628 hr = IDirect3DRMTexture_InitFromSurface(texture1, NULL);
6629 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6630 IDirect3DRMTexture_Release(texture1);
6632 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6633 hr = IDirect3DRM2_CreateTextureFromSurface(d3drm2, surface, &texture2);
6634 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6635 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6636 image = IDirect3DRMTexture2_GetImage(texture2);
6637 ok(image == NULL, "Unexpected image, %p.\n", image);
6638 hr = IDirect3DRMTexture2_InitFromSurface(texture2, NULL);
6639 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6640 IDirect3DRMTexture_Release(texture2);
6642 ok(get_refcount((IUnknown *)surface) == 1, "Unexpected surface refcount.\n");
6643 hr = IDirect3DRM3_CreateTextureFromSurface(d3drm3, surface, &texture3);
6644 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6645 ok(get_refcount((IUnknown *)surface) == 2, "Unexpected surface refcount.\n");
6646 image = IDirect3DRMTexture3_GetImage(texture3);
6647 ok(image == NULL, "Unexpected image, %p.\n", image);
6648 hr = IDirect3DRMTexture3_InitFromSurface(texture3, NULL);
6649 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
6650 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, NULL);
6651 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
6652 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &ds);
6653 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
6654 ok(ds == surface, "Expected same surface back.\n");
6655 IDirectDrawSurface_Release(ds);
6657 /* Init already initialized texture with same surface. */
6658 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface);
6659 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6661 /* Init already initialized texture with different surface. */
6662 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface2);
6663 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6665 hr = IDirect3DRMTexture3_GetSurface(texture3, 0, &ds);
6666 ok(SUCCEEDED(hr), "Failed to get surface, hr %#x.\n", hr);
6667 ok(ds == surface, "Expected same surface back.\n");
6668 IDirectDrawSurface_Release(ds);
6670 ref1 = get_refcount((IUnknown *)d3drm1);
6671 ref2 = get_refcount((IUnknown *)d3drm2);
6672 ref3 = get_refcount((IUnknown *)d3drm3);
6673 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
6674 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6675 ok(ref1 < get_refcount((IUnknown *)d3drm1), "Expected d3drm1 reference taken.\n");
6676 ok(ref2 == get_refcount((IUnknown *)d3drm2), "Expected d3drm2 reference unchanged.\n");
6677 ok(ref3 == get_refcount((IUnknown *)d3drm3), "Expected d3drm3 reference unchanged.\n");
6678 /* Release leaked reference to d3drm1 */
6679 IDirect3DRM_Release(d3drm1);
6681 IDirect3DRMTexture_Release(texture3);
6683 /* Create from image, initialize from surface. */
6684 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
6685 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
6687 ref1 = get_refcount((IUnknown *)d3drm1);
6688 ref2 = get_refcount((IUnknown *)d3drm2);
6689 ref3 = get_refcount((IUnknown *)d3drm3);
6690 hr = IDirect3DRMTexture3_InitFromSurface(texture3, surface);
6691 ok(hr == D3DRMERR_BADOBJECT, "Expected a failure, hr %#x.\n", hr);
6692 ok(ref1 < get_refcount((IUnknown *)d3drm1), "Expected d3drm1 reference taken.\n");
6693 ok(ref2 == get_refcount((IUnknown *)d3drm2), "Expected d3drm2 reference unchanged.\n");
6694 ok(ref3 == get_refcount((IUnknown *)d3drm3), "Expected d3drm3 reference unchanged.\n");
6695 /* Release leaked reference to d3drm1 */
6696 IDirect3DRM_Release(d3drm1);
6697 IDirect3DRMTexture3_Release(texture3);
6699 IDirectDrawSurface_Release(surface2);
6700 IDirectDrawSurface_Release(surface);
6701 IDirect3DRM3_Release(d3drm3);
6702 IDirect3DRM2_Release(d3drm2);
6703 IDirect3DRM_Release(d3drm1);
6704 IDirectDraw_Release(ddraw);
6707 START_TEST(d3drm)
6709 test_MeshBuilder();
6710 test_MeshBuilder3();
6711 test_Mesh();
6712 test_Face();
6713 test_Frame();
6714 test_Device();
6715 test_object();
6716 test_Viewport();
6717 test_Light();
6718 test_Material2();
6719 test_Texture();
6720 test_frame_transform();
6721 test_d3drm_load();
6722 test_frame_mesh_materials();
6723 test_d3drm_qi();
6724 test_frame_qi();
6725 test_device_qi();
6726 test_create_device_from_clipper1();
6727 test_create_device_from_clipper2();
6728 test_create_device_from_clipper3();
6729 test_create_device_from_surface1();
6730 test_create_device_from_surface2();
6731 test_create_device_from_surface3();
6732 test_create_device_from_d3d1();
6733 test_create_device_from_d3d2();
6734 test_create_device_from_d3d3();
6735 test_load_texture();
6736 test_texture_qi();
6737 test_viewport_qi();
6738 test_viewport_clear1();
6739 test_viewport_clear2();
6740 test_create_texture_from_surface();