d3drm/tests: Fix typos in a couple of ok() messages.
[wine.git] / dlls / d3drm / tests / d3drm.c
bloba685b1ed7a15af5e36d05267df33b99d11928cea
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 #define COBJMACROS
23 #include <d3d.h>
24 #include <initguid.h>
25 #include <d3drm.h>
26 #include <d3drmwin.h>
28 #include "wine/test.h"
30 #define CHECK_REFCOUNT(obj,rc) \
31 { \
32 int rc_new = rc; \
33 int count = get_refcount( (IUnknown *)obj ); \
34 ok(count == rc_new, "Invalid refcount. Expected %d got %d\n", rc_new, count); \
37 static ULONG get_refcount(IUnknown *object)
39 IUnknown_AddRef( object );
40 return IUnknown_Release( object );
43 static BOOL match_float(float a, float b)
45 return (a - b) < 0.000001f;
48 static D3DRMMATRIX4D identity = {
49 { 1.0f, 0.0f, 0.0f, 0.0f },
50 { 0.0f, 1.0f, 0.0f, 0.0f },
51 { 0.0f, 0.0f, 1.0f, 0.0f },
52 { 0.0f, 0.0f, 0.0f, 1.0f }
55 static char data_bad_version[] =
56 "xof 0302txt 0064\n"
57 "Header Object\n"
58 "{\n"
59 "1; 2; 3;\n"
60 "}\n";
62 static char data_no_mesh[] =
63 "xof 0302txt 0064\n"
64 "Header Object\n"
65 "{\n"
66 "1; 0; 1;\n"
67 "}\n";
69 static char data_ok[] =
70 "xof 0302txt 0064\n"
71 "Header Object\n"
72 "{\n"
73 "1; 0; 1;\n"
74 "}\n"
75 "Mesh Object\n"
76 "{\n"
77 "4;\n"
78 "1.0; 0.0; 0.0;,\n"
79 "0.0; 1.0; 0.0;,\n"
80 "0.0; 0.0; 1.0;,\n"
81 "1.0; 1.0; 1.0;;\n"
82 "3;\n"
83 "3; 0, 1, 2;,\n"
84 "3; 1, 2, 3;,\n"
85 "3; 3, 1, 2;;\n"
86 "}\n";
88 static char data_full[] =
89 "xof 0302txt 0064\n"
90 "Header { 1; 0; 1; }\n"
91 "Mesh {\n"
92 " 3;\n"
93 " 0.1; 0.2; 0.3;,\n"
94 " 0.4; 0.5; 0.6;,\n"
95 " 0.7; 0.8; 0.9;;\n"
96 " 1;\n"
97 " 3; 0, 1, 2;;\n"
98 " MeshMaterialList {\n"
99 " 1; 1; 0;\n"
100 " Material {\n"
101 " 0.0; 1.0; 0.0; 1.0;;\n"
102 " 30.0;\n"
103 " 1.0; 0.0; 0.0;;\n"
104 " 0.5; 0.5; 0.5;;\n"
105 " TextureFileName {\n"
106 " \"Texture.bmp\";\n"
107 " }\n"
108 " }\n"
109 " }\n"
110 " MeshNormals {\n"
111 " 3;\n"
112 " 1.1; 1.2; 1.3;,\n"
113 " 1.4; 1.5; 1.6;,\n"
114 " 1.7; 1.8; 1.9;;\n"
115 " 1;"
116 " 3; 0, 1, 2;;\n"
117 " }\n"
118 " MeshTextureCoords {\n"
119 " 3;\n"
120 " 0.13; 0.17;,\n"
121 " 0.23; 0.27;,\n"
122 " 0.33; 0.37;;\n"
123 " }\n"
124 "}\n";
126 static char data_d3drm_load[] =
127 "xof 0302txt 0064\n"
128 "Header Object\n"
129 "{\n"
130 "1; 0; 1;\n"
131 "}\n"
132 "Mesh Object1\n"
133 "{\n"
134 " 1;\n"
135 " 0.1; 0.2; 0.3;,\n"
136 " 1;\n"
137 " 3; 0, 1, 2;;\n"
138 "}\n"
139 "Mesh Object2\n"
140 "{\n"
141 " 1;\n"
142 " 0.1; 0.2; 0.3;,\n"
143 " 1;\n"
144 " 3; 0, 1, 2;;\n"
145 "}\n"
146 "Frame Scene\n"
147 "{\n"
148 " {Object1}\n"
149 " {Object2}\n"
150 "}\n"
151 "Material\n"
152 "{\n"
153 " 0.1, 0.2, 0.3, 0.4;;\n"
154 " 0.5;\n"
155 " 0.6, 0.7, 0.8;;\n"
156 " 0.9, 1.0, 1.1;;\n"
157 "}\n";
159 static char data_frame_mesh_materials[] =
160 "xof 0302txt 0064\n"
161 "Header { 1; 0; 1; }\n"
162 "Frame {\n"
163 " Mesh mesh1 {\n"
164 " 5;\n"
165 " 0.1; 0.2; 0.3;,\n"
166 " 0.4; 0.5; 0.6;,\n"
167 " 0.7; 0.8; 0.9;,\n"
168 " 1.1; 1.2; 1.3;,\n"
169 " 1.4; 1.5; 1.6;;\n"
170 " 6;\n"
171 " 3; 0, 1, 2;,\n"
172 " 3; 0, 2, 1;,\n"
173 " 3; 1, 2, 3;,\n"
174 " 3; 1, 3, 2;,\n"
175 " 3; 2, 3, 4;,\n"
176 " 3; 2, 4, 3;;\n"
177 " MeshMaterialList {\n"
178 " 3; 6; 0, 1, 1, 2, 2, 2;\n"
179 " Material mat1 {\n"
180 " 1.0; 0.0; 0.0; 0.1;;\n"
181 " 10.0;\n"
182 " 0.11; 0.12; 0.13;;\n"
183 " 0.14; 0.15; 0.16;;\n"
184 " }\n"
185 " Material mat2 {\n"
186 " 0.0; 1.0; 0.0; 0.2;;\n"
187 " 20.0;\n"
188 " 0.21; 0.22; 0.23;;\n"
189 " 0.24; 0.25; 0.26;;\n"
190 " }\n"
191 " Material mat3 {\n"
192 " 0.0; 0.0; 1.0; 0.3;;\n"
193 " 30.0;\n"
194 " 0.31; 0.32; 0.33;;\n"
195 " 0.34; 0.35; 0.36;;\n"
196 " }\n"
197 " }\n"
198 " }\n"
199 "}\n";
201 static void test_MeshBuilder(void)
203 HRESULT hr;
204 IDirect3DRM *d3drm;
205 IDirect3DRMMeshBuilder *pMeshBuilder;
206 IDirect3DRMMesh *mesh;
207 D3DRMLOADMEMORY info;
208 int val;
209 DWORD val1, val2, val3;
210 D3DVALUE valu, valv;
211 D3DVECTOR v[3];
212 D3DVECTOR n[4];
213 DWORD f[8];
214 char name[10];
215 DWORD size;
216 D3DCOLOR color;
217 CHAR cname[64] = {0};
219 hr = Direct3DRMCreate(&d3drm);
220 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
222 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
223 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
225 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, NULL, cname);
226 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
227 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, NULL, NULL);
228 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
229 size = 1;
230 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, &size, cname);
231 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
232 size = sizeof(cname);
233 hr = IDirect3DRMMeshBuilder_GetClassName(pMeshBuilder, &size, cname);
234 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
235 ok(size == sizeof("Builder"), "wrong size: %u\n", size);
236 ok(!strcmp(cname, "Builder"), "Expected cname to be \"Builder\", but got \"%s\"\n", cname);
238 info.lpMemory = data_bad_version;
239 info.dSize = strlen(data_bad_version);
240 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
241 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
243 info.lpMemory = data_no_mesh;
244 info.dSize = strlen(data_no_mesh);
245 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
246 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
248 info.lpMemory = data_ok;
249 info.dSize = strlen(data_ok);
250 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
251 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
253 size = sizeof(name);
254 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
255 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
256 ok(!strcmp(name, "Object"), "Retrieved name '%s' instead of 'Object'\n", name);
257 size = strlen("Object"); /* No space for null character */
258 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
259 ok(hr == E_INVALIDARG, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
260 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, NULL);
261 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
262 size = sizeof(name);
263 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
264 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
265 ok(size == 0, "Size should be 0 instead of %u\n", size);
266 hr = IDirect3DRMMeshBuilder_SetName(pMeshBuilder, "");
267 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_SetName returned hr = %x\n", hr);
268 size = sizeof(name);
269 hr = IDirect3DRMMeshBuilder_GetName(pMeshBuilder, &size, name);
270 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned hr = %x\n", hr);
271 ok(!strcmp(name, ""), "Retrieved name '%s' instead of ''\n", name);
273 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
274 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
276 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
277 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
279 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, NULL, &val2, NULL, &val3, NULL);
280 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
281 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
282 ok(val2 == 4, "Wrong number of normals %d (must be 4)\n", val2);
283 ok(val3 == 22, "Wrong number of face data bytes %d (must be 22)\n", val3);
285 /* Check that Load method generated default normals */
286 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, NULL, &val2, n, NULL, NULL);
287 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
288 ok(match_float(U1(n[0]).x, 0.577350f), "Wrong component n[0].x = %f (expected %f)\n", U1(n[0]).x, 0.577350f);
289 ok(match_float(U2(n[0]).y, 0.577350f), "Wrong component n[0].y = %f (expected %f)\n", U2(n[0]).y, 0.577350f);
290 ok(match_float(U3(n[0]).z, 0.577350f), "Wrong component n[0].z = %f (expected %f)\n", U3(n[0]).z, 0.577350f);
291 ok(match_float(U1(n[1]).x, -0.229416f), "Wrong component n[1].x = %f (expected %f)\n", U1(n[1]).x, -0.229416f);
292 ok(match_float(U2(n[1]).y, 0.688247f), "Wrong component n[1].y = %f (expected %f)\n", U2(n[1]).y, 0.688247f);
293 ok(match_float(U3(n[1]).z, 0.688247f), "Wrong component n[1].z = %f (expected %f)\n", U3(n[1]).z, 0.688247f);
294 ok(match_float(U1(n[2]).x, -0.229416f), "Wrong component n[2].x = %f (expected %f)\n", U1(n[2]).x, -0.229416f);
295 ok(match_float(U2(n[2]).y, 0.688247f), "Wrong component n[2].y = %f (expected %f)\n", U2(n[2]).y, 0.688247f);
296 ok(match_float(U3(n[2]).z, 0.688247f), "Wrong component n[2].z = %f (expected %f)\n", U3(n[2]).z, 0.688247f);
297 ok(match_float(U1(n[3]).x, -0.577350f), "Wrong component n[3].x = %f (expected %f)\n", U1(n[3]).x, -0.577350f);
298 ok(match_float(U2(n[3]).y, 0.577350f), "Wrong component n[3].y = %f (expected %f)\n", U2(n[3]).y, 0.577350f);
299 ok(match_float(U3(n[3]).z, 0.577350f), "Wrong component n[3].z = %f (expected %f)\n", U3(n[3]).z, 0.577350f);
301 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
302 valu = 1.23f;
303 valv = 3.21f;
304 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
305 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
306 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
307 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
308 valu = 1.23f;
309 valv = 3.21f;
310 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 1, &valu, &valv);
311 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
312 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
313 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
314 valu = 1.23f;
315 valv = 3.21f;
316 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 2, &valu, &valv);
317 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
318 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
319 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
320 valu = 1.23f;
321 valv = 3.21f;
322 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 3, &valu, &valv);
323 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
324 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
325 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
326 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 4, &valu, &valv);
327 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
329 valu = 1.23f;
330 valv = 3.21f;
331 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 0, valu, valv);
332 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
333 hr = IDirect3DRMMeshBuilder_SetTextureCoordinates(pMeshBuilder, 4, valu, valv);
334 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
336 valu = 0.0f;
337 valv = 0.0f;
338 hr = IDirect3DRMMeshBuilder_GetTextureCoordinates(pMeshBuilder, 0, &valu, &valv);
339 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
340 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
341 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
343 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
345 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &pMeshBuilder);
346 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
348 /* No group in mesh when mesh builder is not loaded */
349 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
350 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
351 if (hr == D3DRM_OK)
353 DWORD nb_groups;
355 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
356 ok(nb_groups == 0, "GetCroupCount returned %u\n", nb_groups);
358 IDirect3DRMMesh_Release(mesh);
361 info.lpMemory = data_full;
362 info.dSize = strlen(data_full);
363 hr = IDirect3DRMMeshBuilder_Load(pMeshBuilder, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
364 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
366 val = IDirect3DRMMeshBuilder_GetVertexCount(pMeshBuilder);
367 ok(val == 3, "Wrong number of vertices %d (must be 3)\n", val);
369 val = IDirect3DRMMeshBuilder_GetFaceCount(pMeshBuilder);
370 ok(val == 1, "Wrong number of faces %d (must be 1)\n", val);
372 /* Check no buffer size and too small buffer size errors */
373 val1 = 1; val2 = 3; val3 = 8;
374 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
375 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
376 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, NULL, v, &val2, n, &val3, f);
377 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
378 val1 = 3; val2 = 1; val3 = 8;
379 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
380 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
381 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, NULL, n, &val3, f);
382 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
383 val1 = 3; val2 = 3; val3 = 1;
384 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
385 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
386 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, NULL, f);
387 ok(hr == D3DRMERR_BADVALUE, "IDirect3DRMMeshBuilder_GetVertices returned %#x\n", hr);
389 val1 = 3; val2 = 3; val3 = 8;
390 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
391 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
392 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
393 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
394 ok(val3 == 8, "Wrong number of face data bytes %d (must be 8)\n", val3);
395 ok(U1(v[0]).x == 0.1f, "Wrong component v[0].x = %f (expected 0.1)\n", U1(v[0]).x);
396 ok(U2(v[0]).y == 0.2f, "Wrong component v[0].y = %f (expected 0.2)\n", U2(v[0]).y);
397 ok(U3(v[0]).z == 0.3f, "Wrong component v[0].z = %f (expected 0.3)\n", U3(v[0]).z);
398 ok(U1(v[1]).x == 0.4f, "Wrong component v[1].x = %f (expected 0.4)\n", U1(v[1]).x);
399 ok(U2(v[1]).y == 0.5f, "Wrong component v[1].y = %f (expected 0.5)\n", U2(v[1]).y);
400 ok(U3(v[1]).z == 0.6f, "Wrong component v[1].z = %f (expected 0.6)\n", U3(v[1]).z);
401 ok(U1(v[2]).x == 0.7f, "Wrong component v[2].x = %f (expected 0.7)\n", U1(v[2]).x);
402 ok(U2(v[2]).y == 0.8f, "Wrong component v[2].y = %f (expected 0.8)\n", U2(v[2]).y);
403 ok(U3(v[2]).z == 0.9f, "Wrong component v[2].z = %f (expected 0.9)\n", U3(v[2]).z);
404 ok(U1(n[0]).x == 1.1f, "Wrong component n[0].x = %f (expected 1.1)\n", U1(n[0]).x);
405 ok(U2(n[0]).y == 1.2f, "Wrong component n[0].y = %f (expected 1.2)\n", U2(n[0]).y);
406 ok(U3(n[0]).z == 1.3f, "Wrong component n[0].z = %f (expected 1.3)\n", U3(n[0]).z);
407 ok(U1(n[1]).x == 1.4f, "Wrong component n[1].x = %f (expected 1.4)\n", U1(n[1]).x);
408 ok(U2(n[1]).y == 1.5f, "Wrong component n[1].y = %f (expected 1.5)\n", U2(n[1]).y);
409 ok(U3(n[1]).z == 1.6f, "Wrong component n[1].z = %f (expected 1.6)\n", U3(n[1]).z);
410 ok(U1(n[2]).x == 1.7f, "Wrong component n[2].x = %f (expected 1.7)\n", U1(n[2]).x);
411 ok(U2(n[2]).y == 1.8f, "Wrong component n[2].y = %f (expected 1.8)\n", U2(n[2]).y);
412 ok(U3(n[2]).z == 1.9f, "Wrong component n[2].z = %f (expected 1.9)\n", U3(n[2]).z);
413 ok(f[0] == 3 , "Wrong component f[0] = %d (expected 3)\n", f[0]);
414 ok(f[1] == 0 , "Wrong component f[1] = %d (expected 0)\n", f[1]);
415 ok(f[2] == 0 , "Wrong component f[2] = %d (expected 0)\n", f[2]);
416 ok(f[3] == 1 , "Wrong component f[3] = %d (expected 1)\n", f[3]);
417 ok(f[4] == 1 , "Wrong component f[4] = %d (expected 1)\n", f[4]);
418 ok(f[5] == 2 , "Wrong component f[5] = %d (expected 2)\n", f[5]);
419 ok(f[6] == 2 , "Wrong component f[6] = %d (expected 2)\n", f[6]);
420 ok(f[7] == 0 , "Wrong component f[7] = %d (expected 0)\n", f[7]);
422 hr = IDirect3DRMMeshBuilder_CreateMesh(pMeshBuilder, &mesh);
423 ok(hr == D3DRM_OK, "CreateMesh failed returning hr = %x\n", hr);
424 if (hr == D3DRM_OK)
426 DWORD nb_groups;
427 unsigned nb_vertices, nb_faces, nb_face_vertices;
428 DWORD data_size;
429 IDirect3DRMMaterial *material = (IDirect3DRMMaterial *)0xdeadbeef;
430 IDirect3DRMTexture *texture = (IDirect3DRMTexture *)0xdeadbeef;
431 D3DVALUE values[3];
433 nb_groups = IDirect3DRMMesh_GetGroupCount(mesh);
434 ok(nb_groups == 1, "GetCroupCount returned %u\n", nb_groups);
435 hr = IDirect3DRMMesh_GetGroup(mesh, 1, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
436 ok(hr == D3DRMERR_BADVALUE, "GetCroup returned hr = %x\n", hr);
437 hr = IDirect3DRMMesh_GetGroup(mesh, 0, &nb_vertices, &nb_faces, &nb_face_vertices, &data_size, NULL);
438 ok(hr == D3DRM_OK, "GetCroup failed returning hr = %x\n", hr);
439 ok(nb_vertices == 3, "Wrong number of vertices %u (must be 3)\n", nb_vertices);
440 ok(nb_faces == 1, "Wrong number of faces %u (must be 1)\n", nb_faces);
441 ok(nb_face_vertices == 3, "Wrong number of vertices per face %u (must be 3)\n", nb_face_vertices);
442 ok(data_size == 3, "Wrong number of face data bytes %u (must be 3)\n", data_size);
443 color = IDirect3DRMMesh_GetGroupColor(mesh, 0);
444 ok(color == 0xff00ff00, "Wrong color returned %#x instead of %#x\n", color, 0xff00ff00);
445 hr = IDirect3DRMMesh_GetGroupTexture(mesh, 0, &texture);
446 ok(hr == D3DRM_OK, "GetCroupTexture failed returning hr = %x\n", hr);
447 ok(texture == NULL, "No texture should be present\n");
448 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, 0, &material);
449 ok(hr == D3DRM_OK, "GetCroupMaterial failed returning hr = %x\n", hr);
450 ok(material != NULL, "No material present\n");
451 hr = IDirect3DRMMaterial_GetEmissive(material, &values[0], &values[1], &values[2]);
452 ok(hr == D3DRM_OK, "Failed to get emissive color, hr %#x.\n", hr);
453 ok(values[0] == 0.5f, "Got unexpected red component %.8e.\n", values[0]);
454 ok(values[1] == 0.5f, "Got unexpected green component %.8e.\n", values[1]);
455 ok(values[2] == 0.5f, "Got unexpected blue component %.8e.\n", values[2]);
456 hr = IDirect3DRMMaterial_GetSpecular(material, &values[0], &values[1], &values[2]);
457 ok(hr == D3DRM_OK, "Failed to get specular color, hr %#x.\n", hr);
458 ok(values[0] == 1.0f, "Got unexpected red component %.8e.\n", values[0]);
459 ok(values[1] == 0.0f, "Got unexpected green component %.8e.\n", values[1]);
460 ok(values[2] == 0.0f, "Got unexpected blue component %.8e.\n", values[2]);
461 values[0] = IDirect3DRMMaterial_GetPower(material);
462 ok(values[0] == 30.0f, "Got unexpected power value %.8e.\n", values[0]);
463 IDirect3DRMMaterial_Release(material);
465 IDirect3DRMMesh_Release(mesh);
468 hr = IDirect3DRMMeshBuilder_Scale(pMeshBuilder, 2, 3 ,4);
469 ok(hr == D3DRM_OK, "Scale failed returning hr = %x\n", hr);
471 hr = IDirect3DRMMeshBuilder_GetVertices(pMeshBuilder, &val1, v, &val2, n, &val3, f);
472 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
473 ok(val2 == 3, "Wrong number of normals %d (must be 3)\n", val2);
474 ok(val1 == 3, "Wrong number of vertices %d (must be 3)\n", val1);
475 ok(U1(v[0]).x == 0.1f*2, "Wrong component v[0].x = %f (expected %f)\n", U1(v[0]).x, 0.1f*2);
476 ok(U2(v[0]).y == 0.2f*3, "Wrong component v[0].y = %f (expected %f)\n", U2(v[0]).y, 0.2f*3);
477 ok(U3(v[0]).z == 0.3f*4, "Wrong component v[0].z = %f (expected %f)\n", U3(v[0]).z, 0.3f*4);
478 ok(U1(v[1]).x == 0.4f*2, "Wrong component v[1].x = %f (expected %f)\n", U1(v[1]).x, 0.4f*2);
479 ok(U2(v[1]).y == 0.5f*3, "Wrong component v[1].y = %f (expected %f)\n", U2(v[1]).y, 0.5f*3);
480 ok(U3(v[1]).z == 0.6f*4, "Wrong component v[1].z = %f (expected %f)\n", U3(v[1]).z, 0.6f*4);
481 ok(U1(v[2]).x == 0.7f*2, "Wrong component v[2].x = %f (expected %f)\n", U1(v[2]).x, 0.7f*2);
482 ok(U2(v[2]).y == 0.8f*3, "Wrong component v[2].y = %f (expected %f)\n", U2(v[2]).y, 0.8f*3);
483 ok(U3(v[2]).z == 0.9f*4, "Wrong component v[2].z = %f (expected %f)\n", U3(v[2]).z, 0.9f*4);
484 /* Normals are not affected by Scale */
485 ok(U1(n[0]).x == 1.1f, "Wrong component n[0].x = %f (expected %f)\n", U1(n[0]).x, 1.1f);
486 ok(U2(n[0]).y == 1.2f, "Wrong component n[0].y = %f (expected %f)\n", U2(n[0]).y, 1.2f);
487 ok(U3(n[0]).z == 1.3f, "Wrong component n[0].z = %f (expected %f)\n", U3(n[0]).z, 1.3f);
488 ok(U1(n[1]).x == 1.4f, "Wrong component n[1].x = %f (expected %f)\n", U1(n[1]).x, 1.4f);
489 ok(U2(n[1]).y == 1.5f, "Wrong component n[1].y = %f (expected %f)\n", U2(n[1]).y, 1.5f);
490 ok(U3(n[1]).z == 1.6f, "Wrong component n[1].z = %f (expected %f)\n", U3(n[1]).z, 1.6f);
491 ok(U1(n[2]).x == 1.7f, "Wrong component n[2].x = %f (expected %f)\n", U1(n[2]).x, 1.7f);
492 ok(U2(n[2]).y == 1.8f, "Wrong component n[2].y = %f (expected %f)\n", U2(n[2]).y, 1.8f);
493 ok(U3(n[2]).z == 1.9f, "Wrong component n[2].z = %f (expected %f)\n", U3(n[2]).z, 1.9f);
495 IDirect3DRMMeshBuilder_Release(pMeshBuilder);
497 IDirect3DRM_Release(d3drm);
500 static void test_MeshBuilder3(void)
502 HRESULT hr;
503 IDirect3DRM *d3drm;
504 IDirect3DRM3 *d3drm3;
505 IDirect3DRMMeshBuilder3 *pMeshBuilder3;
506 D3DRMLOADMEMORY info;
507 int val;
508 DWORD val1;
509 D3DVALUE valu, valv;
510 DWORD size;
511 CHAR cname[64] = {0};
513 hr = Direct3DRMCreate(&d3drm);
514 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
516 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
518 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
519 IDirect3DRM_Release(d3drm);
520 return;
523 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &pMeshBuilder3);
524 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
526 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, NULL, cname);
527 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
528 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, NULL, NULL);
529 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
530 size = 1;
531 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, &size, cname);
532 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
533 size = sizeof(cname);
534 hr = IDirect3DRMMeshBuilder3_GetClassName(pMeshBuilder3, &size, cname);
535 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
536 ok(size == sizeof("Builder"), "wrong size: %u\n", size);
537 ok(!strcmp(cname, "Builder"), "Expected cname to be \"Builder\", but got \"%s\"\n", cname);
539 info.lpMemory = data_bad_version;
540 info.dSize = strlen(data_bad_version);
541 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
542 ok(hr == D3DRMERR_BADFILE, "Should have returned D3DRMERR_BADFILE (hr = %x)\n", hr);
544 info.lpMemory = data_no_mesh;
545 info.dSize = strlen(data_no_mesh);
546 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
547 ok(hr == D3DRMERR_NOTFOUND, "Should have returned D3DRMERR_NOTFOUND (hr = %x)\n", hr);
549 info.lpMemory = data_ok;
550 info.dSize = strlen(data_ok);
551 hr = IDirect3DRMMeshBuilder3_Load(pMeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
552 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
554 val = IDirect3DRMMeshBuilder3_GetVertexCount(pMeshBuilder3);
555 ok(val == 4, "Wrong number of vertices %d (must be 4)\n", val);
557 val = IDirect3DRMMeshBuilder3_GetFaceCount(pMeshBuilder3);
558 ok(val == 3, "Wrong number of faces %d (must be 3)\n", val);
560 hr = IDirect3DRMMeshBuilder3_GetVertices(pMeshBuilder3, 0, &val1, NULL);
561 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
562 ok(val1 == 4, "Wrong number of vertices %d (must be 4)\n", val1);
564 /* Check that Load method generated default texture coordinates (0.0f, 0.0f) for each vertex */
565 valu = 1.23f;
566 valv = 3.21f;
567 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
568 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
569 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
570 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
571 valu = 1.23f;
572 valv = 3.21f;
573 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 1, &valu, &valv);
574 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
575 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
576 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
577 valu = 1.23f;
578 valv = 3.21f;
579 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 2, &valu, &valv);
580 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
581 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
582 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
583 valu = 1.23f;
584 valv = 3.21f;
585 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 3, &valu, &valv);
586 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
587 ok(valu == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valu);
588 ok(valv == 0.0f, "Wrong coordinate %f (must be 0.0)\n", valv);
589 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 4, &valu, &valv);
590 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
592 valu = 1.23f;
593 valv = 3.21f;
594 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 0, valu, valv);
595 ok(hr == D3DRM_OK, "Cannot set texture coordinates (hr = %x)\n", hr);
596 hr = IDirect3DRMMeshBuilder3_SetTextureCoordinates(pMeshBuilder3, 4, valu, valv);
597 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
599 valu = 0.0f;
600 valv = 0.0f;
601 hr = IDirect3DRMMeshBuilder3_GetTextureCoordinates(pMeshBuilder3, 0, &valu, &valv);
602 ok(hr == D3DRM_OK, "Cannot get texture coordinates (hr = %x)\n", hr);
603 ok(valu == 1.23f, "Wrong coordinate %f (must be 1.23)\n", valu);
604 ok(valv == 3.21f, "Wrong coordinate %f (must be 3.21)\n", valv);
606 IDirect3DRMMeshBuilder3_Release(pMeshBuilder3);
607 IDirect3DRM3_Release(d3drm3);
608 IDirect3DRM_Release(d3drm);
611 static void test_Mesh(void)
613 HRESULT hr;
614 IDirect3DRM *d3drm;
615 IDirect3DRMMesh *mesh;
616 DWORD size;
617 CHAR cname[64] = {0};
619 hr = Direct3DRMCreate(&d3drm);
620 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
622 hr = IDirect3DRM_CreateMesh(d3drm, &mesh);
623 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMesh interface (hr = %x)\n", hr);
625 hr = IDirect3DRMMesh_GetClassName(mesh, NULL, cname);
626 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
627 hr = IDirect3DRMMesh_GetClassName(mesh, NULL, NULL);
628 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
629 size = 1;
630 hr = IDirect3DRMMesh_GetClassName(mesh, &size, cname);
631 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
632 size = sizeof(cname);
633 hr = IDirect3DRMMesh_GetClassName(mesh, &size, cname);
634 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
635 ok(size == sizeof("Mesh"), "wrong size: %u\n", size);
636 ok(!strcmp(cname, "Mesh"), "Expected cname to be \"Mesh\", but got \"%s\"\n", cname);
638 IDirect3DRMMesh_Release(mesh);
640 IDirect3DRM_Release(d3drm);
643 static void test_Face(void)
645 HRESULT hr;
646 IDirect3DRM *d3drm;
647 IDirect3DRM2 *d3drm2;
648 IDirect3DRM3 *d3drm3;
649 IDirect3DRMMeshBuilder2 *MeshBuilder2;
650 IDirect3DRMMeshBuilder3 *MeshBuilder3;
651 IDirect3DRMFace *face1;
652 IDirect3DRMFace2 *face2;
653 IDirect3DRMFaceArray *array1;
654 D3DRMLOADMEMORY info;
655 D3DVECTOR v1[4], n1[4], v2[4], n2[4];
656 DWORD count;
657 CHAR cname[64] = {0};
658 int icount;
660 hr = Direct3DRMCreate(&d3drm);
661 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
663 hr = IDirect3DRM_CreateFace(d3drm, &face1);
664 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
665 if (FAILED(hr))
667 skip("Cannot get IDirect3DRMFace interface (hr = %x), skipping tests\n", hr);
668 IDirect3DRM_Release(d3drm);
669 return;
672 hr = IDirect3DRMFace_GetClassName(face1, NULL, cname);
673 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
674 hr = IDirect3DRMFace_GetClassName(face1, NULL, NULL);
675 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
676 count = 1;
677 hr = IDirect3DRMFace_GetClassName(face1, &count, cname);
678 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
679 count = sizeof(cname);
680 hr = IDirect3DRMFace_GetClassName(face1, &count, cname);
681 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
682 ok(count == sizeof("Face"), "wrong size: %u\n", count);
683 ok(!strcmp(cname, "Face"), "Expected cname to be \"Face\", but got \"%s\"\n", cname);
685 icount = IDirect3DRMFace_GetVertexCount(face1);
686 ok(!icount, "wrong VertexCount: %i\n", icount);
688 IDirect3DRMFace_Release(face1);
690 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM2, (void **)&d3drm2)))
692 win_skip("Cannot get IDirect3DRM2 interface (hr = %x), skipping tests\n", hr);
693 IDirect3DRM_Release(d3drm);
694 return;
697 hr = IDirect3DRM2_CreateMeshBuilder(d3drm2, &MeshBuilder2);
698 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder2 interface (hr = %x)\n", hr);
700 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
701 ok(!icount, "wrong FaceCount: %i\n", icount);
703 array1 = NULL;
704 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
705 todo_wine
706 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
708 hr = IDirect3DRMMeshBuilder2_CreateFace(MeshBuilder2, &face1);
709 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace interface (hr = %x)\n", hr);
711 icount = IDirect3DRMMeshBuilder2_GetFaceCount(MeshBuilder2);
712 todo_wine
713 ok(icount == 1, "wrong FaceCount: %i\n", icount);
715 array1 = NULL;
716 hr = IDirect3DRMMeshBuilder2_GetFaces(MeshBuilder2, &array1);
717 todo_wine
718 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
719 todo_wine
720 ok(array1 != NULL, "pArray = %p\n", array1);
721 if (array1)
723 IDirect3DRMFace *face;
724 count = IDirect3DRMFaceArray_GetSize(array1);
725 ok(count == 1, "count = %u\n", count);
726 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
727 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
728 IDirect3DRMFace_Release(face);
729 IDirect3DRMFaceArray_Release(array1);
732 icount = IDirect3DRMFace_GetVertexCount(face1);
733 ok(!icount, "wrong VertexCount: %i\n", icount);
735 IDirect3DRMFace_Release(face1);
736 IDirect3DRMMeshBuilder2_Release(MeshBuilder2);
738 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
740 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
741 IDirect3DRM_Release(d3drm);
742 return;
745 hr = IDirect3DRM3_CreateMeshBuilder(d3drm3, &MeshBuilder3);
746 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder3 interface (hr = %x)\n", hr);
748 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
749 ok(!icount, "wrong FaceCount: %i\n", icount);
751 hr = IDirect3DRMMeshBuilder3_CreateFace(MeshBuilder3, &face2);
752 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFace2 interface (hr = %x)\n", hr);
754 hr = IDirect3DRMFace2_GetClassName(face2, NULL, cname);
755 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
756 hr = IDirect3DRMFace2_GetClassName(face2, NULL, NULL);
757 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
758 count = 1;
759 hr = IDirect3DRMFace2_GetClassName(face2, &count, cname);
760 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
761 count = sizeof(cname);
762 hr = IDirect3DRMFace2_GetClassName(face2, &count, cname);
763 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
764 ok(count == sizeof("Face"), "wrong size: %u\n", count);
765 ok(!strcmp(cname, "Face"), "Expected cname to be \"Face\", but got \"%s\"\n", cname);
767 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
768 todo_wine
769 ok(icount == 1, "wrong FaceCount: %i\n", icount);
771 array1 = NULL;
772 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
773 todo_wine
774 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
775 todo_wine
776 ok(array1 != NULL, "pArray = %p\n", array1);
777 if (array1)
779 IDirect3DRMFace *face;
780 count = IDirect3DRMFaceArray_GetSize(array1);
781 ok(count == 1, "count = %u\n", count);
782 hr = IDirect3DRMFaceArray_GetElement(array1, 0, &face);
783 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
784 IDirect3DRMFace_Release(face);
785 IDirect3DRMFaceArray_Release(array1);
788 icount = IDirect3DRMFace2_GetVertexCount(face2);
789 ok(!icount, "wrong VertexCount: %i\n", icount);
791 info.lpMemory = data_ok;
792 info.dSize = strlen(data_ok);
793 hr = IDirect3DRMMeshBuilder3_Load(MeshBuilder3, &info, NULL, D3DRMLOAD_FROMMEMORY, NULL, NULL);
794 ok(hr == D3DRM_OK, "Cannot load mesh data (hr = %x)\n", hr);
796 icount = IDirect3DRMMeshBuilder3_GetVertexCount(MeshBuilder3);
797 ok(icount == 4, "Wrong number of vertices %d (must be 4)\n", icount);
799 icount = IDirect3DRMMeshBuilder3_GetNormalCount(MeshBuilder3);
800 ok(icount == 4, "Wrong number of normals %d (must be 4)\n", icount);
802 icount = IDirect3DRMMeshBuilder3_GetFaceCount(MeshBuilder3);
803 todo_wine
804 ok(icount == 4, "Wrong number of faces %d (must be 4)\n", icount);
806 count = 4;
807 hr = IDirect3DRMMeshBuilder3_GetVertices(MeshBuilder3, 0, &count, v1);
808 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
809 ok(count == 4, "Wrong number of vertices %d (must be 4)\n", count);
811 hr = IDirect3DRMMeshBuilder3_GetNormals(MeshBuilder3, 0, &count, n1);
812 ok(hr == D3DRM_OK, "Cannot get normals information (hr = %x)\n", hr);
813 ok(count == 4, "Wrong number of normals %d (must be 4)\n", count);
815 array1 = NULL;
816 hr = IDirect3DRMMeshBuilder3_GetFaces(MeshBuilder3, &array1);
817 todo_wine
818 ok(hr == D3DRM_OK, "Cannot get FaceArray (hr = %x)\n", hr);
819 todo_wine
820 ok(array1 != NULL, "pArray = %p\n", array1);
821 if (array1)
823 IDirect3DRMFace *face;
824 count = IDirect3DRMFaceArray_GetSize(array1);
825 ok(count == 4, "count = %u\n", count);
826 hr = IDirect3DRMFaceArray_GetElement(array1, 1, &face);
827 ok(hr == D3DRM_OK, "Cannot get face (hr = %x)\n", hr);
828 hr = IDirect3DRMFace_GetVertices(face, &count, v2, n2);
829 ok(hr == D3DRM_OK, "Cannot get vertices information (hr = %x)\n", hr);
830 ok(count == 3, "Wrong number of vertices %d (must be 3)\n", count);
831 ok(U1(v2[0]).x == U1(v1[0]).x, "Wrong component v2[0].x = %f (expected %f)\n",
832 U1(v2[0]).x, U1(v1[0]).x);
833 ok(U2(v2[0]).y == U2(v1[0]).y, "Wrong component v2[0].y = %f (expected %f)\n",
834 U2(v2[0]).y, U2(v1[0]).y);
835 ok(U3(v2[0]).z == U3(v1[0]).z, "Wrong component v2[0].z = %f (expected %f)\n",
836 U3(v2[0]).z, U3(v1[0]).z);
837 ok(U1(v2[1]).x == U1(v1[1]).x, "Wrong component v2[1].x = %f (expected %f)\n",
838 U1(v2[1]).x, U1(v1[1]).x);
839 ok(U2(v2[1]).y == U2(v1[1]).y, "Wrong component v2[1].y = %f (expected %f)\n",
840 U2(v2[1]).y, U2(v1[1]).y);
841 ok(U3(v2[1]).z == U3(v1[1]).z, "Wrong component v2[1].z = %f (expected %f)\n",
842 U3(v2[1]).z, U3(v1[1]).z);
843 ok(U1(v2[2]).x == U1(v1[2]).x, "Wrong component v2[2].x = %f (expected %f)\n",
844 U1(v2[2]).x, U1(v1[2]).x);
845 ok(U2(v2[2]).y == U2(v1[2]).y, "Wrong component v2[2].y = %f (expected %f)\n",
846 U2(v2[2]).y, U2(v1[2]).y);
847 ok(U3(v2[2]).z == U3(v1[2]).z, "Wrong component v2[2].z = %f (expected %f)\n",
848 U3(v2[2]).z, U3(v1[2]).z);
850 ok(U1(n2[0]).x == U1(n1[0]).x, "Wrong component n2[0].x = %f (expected %f)\n",
851 U1(n2[0]).x, U1(n1[0]).x);
852 ok(U2(n2[0]).y == U2(n1[0]).y, "Wrong component n2[0].y = %f (expected %f)\n",
853 U2(n2[0]).y, U2(n1[0]).y);
854 ok(U3(n2[0]).z == U3(n1[0]).z, "Wrong component n2[0].z = %f (expected %f)\n",
855 U3(n2[0]).z, U3(n1[0]).z);
856 ok(U1(n2[1]).x == U1(n1[1]).x, "Wrong component n2[1].x = %f (expected %f)\n",
857 U1(n2[1]).x, U1(n1[1]).x);
858 ok(U2(n2[1]).y == U2(n1[1]).y, "Wrong component n2[1].y = %f (expected %f)\n",
859 U2(n2[1]).y, U2(n1[1]).y);
860 ok(U3(n2[1]).z == U3(n1[1]).z, "Wrong component n2[1].z = %f (expected %f)\n",
861 U3(n2[1]).z, U3(n1[1]).z);
862 ok(U1(n2[2]).x == U1(n1[2]).x, "Wrong component n2[2].x = %f (expected %f)\n",
863 U1(n2[2]).x, U1(n1[2]).x);
864 ok(U2(n2[2]).y == U2(n1[2]).y, "Wrong component n2[2].y = %f (expected %f)\n",
865 U2(n2[2]).y, U2(n1[2]).y);
866 ok(U3(n2[2]).z == U3(n1[2]).z, "Wrong component n2[2].z = %f (expected %f)\n",
867 U3(n2[2]).z, U3(n1[2]).z);
869 IDirect3DRMFace_Release(face);
870 IDirect3DRMFaceArray_Release(array1);
873 IDirect3DRMFace2_Release(face2);
874 IDirect3DRMMeshBuilder3_Release(MeshBuilder3);
875 IDirect3DRM3_Release(d3drm3);
876 IDirect3DRM2_Release(d3drm2);
877 IDirect3DRM_Release(d3drm);
880 static void test_Frame(void)
882 HRESULT hr;
883 IDirect3DRM *d3drm;
884 IDirect3DRMFrame *pFrameC;
885 IDirect3DRMFrame *pFrameP1;
886 IDirect3DRMFrame *pFrameP2;
887 IDirect3DRMFrame *pFrameTmp;
888 IDirect3DRMFrameArray *frame_array;
889 IDirect3DRMMeshBuilder *mesh_builder;
890 IDirect3DRMVisual *visual1;
891 IDirect3DRMVisual *visual_tmp;
892 IDirect3DRMVisualArray *visual_array;
893 IDirect3DRMLight *light1;
894 IDirect3DRMLight *light_tmp;
895 IDirect3DRMLightArray *light_array;
896 D3DCOLOR color;
897 DWORD count;
898 CHAR cname[64] = {0};
900 hr = Direct3DRMCreate(&d3drm);
901 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
903 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameC);
904 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
905 CHECK_REFCOUNT(pFrameC, 1);
907 hr = IDirect3DRMFrame_GetClassName(pFrameC, NULL, cname);
908 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
909 hr = IDirect3DRMFrame_GetClassName(pFrameC, NULL, NULL);
910 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
911 count = 1;
912 hr = IDirect3DRMFrame_GetClassName(pFrameC, &count, cname);
913 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
914 count = sizeof(cname);
915 hr = IDirect3DRMFrame_GetClassName(pFrameC, &count, cname);
916 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
917 ok(count == sizeof("Frame"), "wrong size: %u\n", count);
918 ok(!strcmp(cname, "Frame"), "Expected cname to be \"Frame\", but got \"%s\"\n", cname);
920 hr = IDirect3DRMFrame_GetParent(pFrameC, NULL);
921 ok(hr == D3DRMERR_BADVALUE, "Should fail and return D3DRM_BADVALUE (hr = %x)\n", hr);
922 pFrameTmp = (void*)0xdeadbeef;
923 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
924 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
925 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
926 CHECK_REFCOUNT(pFrameC, 1);
928 frame_array = NULL;
929 hr = IDirect3DRMFrame_GetChildren(pFrameC, &frame_array);
930 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
931 ok(!!frame_array, "frame_array = %p\n", frame_array);
932 if (frame_array)
934 count = IDirect3DRMFrameArray_GetSize(frame_array);
935 ok(count == 0, "count = %u\n", count);
936 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
937 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
938 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
939 IDirect3DRMFrameArray_Release(frame_array);
942 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP1);
943 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
945 /* GetParent with NULL pointer */
946 hr = IDirect3DRMFrame_GetParent(pFrameP1, NULL);
947 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
948 CHECK_REFCOUNT(pFrameP1, 1);
950 /* [Add/Delete]Child with NULL pointer */
951 hr = IDirect3DRMFrame_AddChild(pFrameP1, NULL);
952 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
953 CHECK_REFCOUNT(pFrameP1, 1);
955 hr = IDirect3DRMFrame_DeleteChild(pFrameP1, NULL);
956 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
957 CHECK_REFCOUNT(pFrameP1, 1);
959 /* Add child to first parent */
960 pFrameTmp = (void*)0xdeadbeef;
961 hr = IDirect3DRMFrame_GetParent(pFrameP1, &pFrameTmp);
962 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
963 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
965 hr = IDirect3DRMFrame_AddChild(pFrameP1, pFrameC);
966 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
967 CHECK_REFCOUNT(pFrameP1, 1);
968 CHECK_REFCOUNT(pFrameC, 2);
970 frame_array = NULL;
971 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
972 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
973 /* In some older version of d3drm, creating IDirect3DRMFrameArray object with GetChildren does not increment refcount of children frames */
974 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
975 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
976 if (frame_array)
978 count = IDirect3DRMFrameArray_GetSize(frame_array);
979 ok(count == 1, "count = %u\n", count);
980 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
981 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
982 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
983 ok((get_refcount((IUnknown*)pFrameC) == 4) || broken(get_refcount((IUnknown*)pFrameC) == 3),
984 "Invalid refcount. Expected 4 (or 3) got %d\n", get_refcount((IUnknown*)pFrameC));
985 IDirect3DRMFrame_Release(pFrameTmp);
986 ok((get_refcount((IUnknown*)pFrameC) == 3) || broken(get_refcount((IUnknown*)pFrameC) == 2),
987 "Invalid refcount. Expected 3 (or 2) got %d\n", get_refcount((IUnknown*)pFrameC));
988 IDirect3DRMFrameArray_Release(frame_array);
989 CHECK_REFCOUNT(pFrameC, 2);
992 pFrameTmp = (void*)0xdeadbeef;
993 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
994 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
995 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
996 CHECK_REFCOUNT(pFrameP1, 2);
997 IDirect3DRMFrame_Release(pFrameTmp);
998 CHECK_REFCOUNT(pFrameP1, 1);
1000 /* Add child to second parent */
1001 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &pFrameP2);
1002 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1004 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1005 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1006 CHECK_REFCOUNT(pFrameC, 2);
1008 frame_array = NULL;
1009 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1010 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1011 if (frame_array)
1013 count = IDirect3DRMFrameArray_GetSize(frame_array);
1014 ok(count == 1, "count = %u\n", count);
1015 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1016 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1017 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1018 IDirect3DRMFrame_Release(pFrameTmp);
1019 IDirect3DRMFrameArray_Release(frame_array);
1022 frame_array = NULL;
1023 hr = IDirect3DRMFrame_GetChildren(pFrameP1, &frame_array);
1024 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1025 if (frame_array)
1027 count = IDirect3DRMFrameArray_GetSize(frame_array);
1028 ok(count == 0, "count = %u\n", count);
1029 pFrameTmp = (void*)0xdeadbeef;
1030 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1031 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1032 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1033 IDirect3DRMFrameArray_Release(frame_array);
1036 pFrameTmp = (void*)0xdeadbeef;
1037 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1038 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1039 ok(pFrameTmp == pFrameP2, "pFrameTmp = %p\n", pFrameTmp);
1040 CHECK_REFCOUNT(pFrameP2, 2);
1041 CHECK_REFCOUNT(pFrameC, 2);
1042 IDirect3DRMFrame_Release(pFrameTmp);
1043 CHECK_REFCOUNT(pFrameP2, 1);
1045 /* Add child again */
1046 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1047 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1048 CHECK_REFCOUNT(pFrameC, 2);
1050 frame_array = NULL;
1051 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1052 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1053 if (frame_array)
1055 count = IDirect3DRMFrameArray_GetSize(frame_array);
1056 ok(count == 1, "count = %u\n", count);
1057 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1058 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1059 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1060 IDirect3DRMFrame_Release(pFrameTmp);
1061 IDirect3DRMFrameArray_Release(frame_array);
1064 /* Delete child */
1065 hr = IDirect3DRMFrame_DeleteChild(pFrameP2, pFrameC);
1066 ok(hr == D3DRM_OK, "Cannot delete child frame (hr = %x)\n", hr);
1067 CHECK_REFCOUNT(pFrameC, 1);
1069 frame_array = NULL;
1070 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1071 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1072 if (frame_array)
1074 count = IDirect3DRMFrameArray_GetSize(frame_array);
1075 ok(count == 0, "count = %u\n", count);
1076 pFrameTmp = (void*)0xdeadbeef;
1077 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1078 ok(hr == D3DRMERR_BADVALUE, "Should have returned D3DRMERR_BADVALUE (hr = %x)\n", hr);
1079 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1080 IDirect3DRMFrameArray_Release(frame_array);
1083 pFrameTmp = (void*)0xdeadbeef;
1084 hr = IDirect3DRMFrame_GetParent(pFrameC, &pFrameTmp);
1085 ok(hr == D3DRM_OK, "Cannot get parent frame (hr = %x)\n", hr);
1086 ok(pFrameTmp == NULL, "pFrameTmp = %p\n", pFrameTmp);
1088 /* Add two children */
1089 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameC);
1090 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1091 CHECK_REFCOUNT(pFrameC, 2);
1093 hr = IDirect3DRMFrame_AddChild(pFrameP2, pFrameP1);
1094 ok(hr == D3DRM_OK, "Cannot add child frame (hr = %x)\n", hr);
1095 CHECK_REFCOUNT(pFrameP1, 2);
1097 frame_array = NULL;
1098 hr = IDirect3DRMFrame_GetChildren(pFrameP2, &frame_array);
1099 ok(hr == D3DRM_OK, "Cannot get children (hr = %x)\n", hr);
1100 if (frame_array)
1102 count = IDirect3DRMFrameArray_GetSize(frame_array);
1103 ok(count == 2, "count = %u\n", count);
1104 hr = IDirect3DRMFrameArray_GetElement(frame_array, 0, &pFrameTmp);
1105 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1106 ok(pFrameTmp == pFrameC, "pFrameTmp = %p\n", pFrameTmp);
1107 IDirect3DRMFrame_Release(pFrameTmp);
1108 hr = IDirect3DRMFrameArray_GetElement(frame_array, 1, &pFrameTmp);
1109 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1110 ok(pFrameTmp == pFrameP1, "pFrameTmp = %p\n", pFrameTmp);
1111 IDirect3DRMFrame_Release(pFrameTmp);
1112 IDirect3DRMFrameArray_Release(frame_array);
1115 /* [Add/Delete]Visual with NULL pointer */
1116 hr = IDirect3DRMFrame_AddVisual(pFrameP1, NULL);
1117 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1118 CHECK_REFCOUNT(pFrameP1, 2);
1120 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, NULL);
1121 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1122 CHECK_REFCOUNT(pFrameP1, 2);
1124 /* Create Visual */
1125 hr = IDirect3DRM_CreateMeshBuilder(d3drm, &mesh_builder);
1126 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMeshBuilder interface (hr = %x)\n", hr);
1127 visual1 = (IDirect3DRMVisual *)mesh_builder;
1129 /* Add Visual to first parent */
1130 hr = IDirect3DRMFrame_AddVisual(pFrameP1, visual1);
1131 ok(hr == D3DRM_OK, "Cannot add visual (hr = %x)\n", hr);
1132 CHECK_REFCOUNT(pFrameP1, 2);
1133 CHECK_REFCOUNT(visual1, 2);
1135 visual_array = NULL;
1136 hr = IDirect3DRMFrame_GetVisuals(pFrameP1, &visual_array);
1137 ok(hr == D3DRM_OK, "Cannot get visuals (hr = %x)\n", hr);
1138 if (visual_array)
1140 count = IDirect3DRMVisualArray_GetSize(visual_array);
1141 ok(count == 1, "count = %u\n", count);
1142 hr = IDirect3DRMVisualArray_GetElement(visual_array, 0, &visual_tmp);
1143 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1144 ok(visual_tmp == visual1, "visual_tmp = %p\n", visual_tmp);
1145 IDirect3DRMVisual_Release(visual_tmp);
1146 IDirect3DRMVisualArray_Release(visual_array);
1149 /* Delete Visual */
1150 hr = IDirect3DRMFrame_DeleteVisual(pFrameP1, visual1);
1151 ok(hr == D3DRM_OK, "Cannot delete visual (hr = %x)\n", hr);
1152 CHECK_REFCOUNT(pFrameP1, 2);
1153 IDirect3DRMMeshBuilder_Release(mesh_builder);
1155 /* [Add/Delete]Light with NULL pointer */
1156 hr = IDirect3DRMFrame_AddLight(pFrameP1, NULL);
1157 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1158 CHECK_REFCOUNT(pFrameP1, 2);
1160 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, NULL);
1161 ok(hr == D3DRMERR_BADOBJECT, "Should have returned D3DRMERR_BADOBJECT (hr = %x)\n", hr);
1162 CHECK_REFCOUNT(pFrameP1, 2);
1164 /* Create Light */
1165 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.1, 0.2, 0.3, &light1);
1166 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1168 /* Add Light to first parent */
1169 hr = IDirect3DRMFrame_AddLight(pFrameP1, light1);
1170 ok(hr == D3DRM_OK, "Cannot add light (hr = %x)\n", hr);
1171 CHECK_REFCOUNT(pFrameP1, 2);
1172 CHECK_REFCOUNT(light1, 2);
1174 light_array = NULL;
1175 hr = IDirect3DRMFrame_GetLights(pFrameP1, &light_array);
1176 ok(hr == D3DRM_OK, "Cannot get lights (hr = %x)\n", hr);
1177 if (light_array)
1179 count = IDirect3DRMLightArray_GetSize(light_array);
1180 ok(count == 1, "count = %u\n", count);
1181 hr = IDirect3DRMLightArray_GetElement(light_array, 0, &light_tmp);
1182 ok(hr == D3DRM_OK, "Cannot get element (hr = %x)\n", hr);
1183 ok(light_tmp == light1, "light_tmp = %p\n", light_tmp);
1184 IDirect3DRMLight_Release(light_tmp);
1185 IDirect3DRMLightArray_Release(light_array);
1188 /* Delete Light */
1189 hr = IDirect3DRMFrame_DeleteLight(pFrameP1, light1);
1190 ok(hr == D3DRM_OK, "Cannot delete light (hr = %x)\n", hr);
1191 CHECK_REFCOUNT(pFrameP1, 2);
1192 IDirect3DRMLight_Release(light1);
1194 /* Test SceneBackground on first parent */
1195 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1196 ok(color == 0xff000000, "wrong color (%x)\n", color);
1198 hr = IDirect3DRMFrame_SetSceneBackground(pFrameP1, 0xff180587);
1199 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1200 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1201 ok(color == 0xff180587, "wrong color (%x)\n", color);
1203 hr = IDirect3DRMFrame_SetSceneBackgroundRGB(pFrameP1, 0.5, 0.5, 0.5);
1204 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1205 color = IDirect3DRMFrame_GetSceneBackground(pFrameP1);
1206 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1208 /* Cleanup */
1209 IDirect3DRMFrame_Release(pFrameP2);
1210 CHECK_REFCOUNT(pFrameC, 1);
1211 CHECK_REFCOUNT(pFrameP1, 1);
1213 IDirect3DRMFrame_Release(pFrameC);
1214 IDirect3DRMFrame_Release(pFrameP1);
1216 IDirect3DRM_Release(d3drm);
1219 struct destroy_context
1221 IDirect3DRMObject *obj;
1222 unsigned int test_idx;
1223 int called;
1226 struct callback_order
1228 void *callback;
1229 void *context;
1230 } corder[3], d3drm_corder[3];
1232 static void CDECL destroy_callback(IDirect3DRMObject *obj, void *arg)
1234 struct destroy_context *ctxt = arg;
1235 ok(ctxt->called == 1 || ctxt->called == 2, "got called counter %d\n", ctxt->called);
1236 ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
1237 d3drm_corder[ctxt->called].callback = &destroy_callback;
1238 d3drm_corder[ctxt->called++].context = ctxt;
1241 static void CDECL destroy_callback1(IDirect3DRMObject *obj, void *arg)
1243 struct destroy_context *ctxt = (struct destroy_context*)arg;
1244 ok(ctxt->called == 0, "got called counter %d\n", ctxt->called);
1245 ok(obj == ctxt->obj, "called with %p, expected %p\n", obj, ctxt->obj);
1246 d3drm_corder[ctxt->called].callback = &destroy_callback1;
1247 d3drm_corder[ctxt->called++].context = ctxt;
1250 static void test_destroy_callback(unsigned int test_idx, REFCLSID clsid, REFIID iid)
1252 struct destroy_context context;
1253 IDirect3DRMObject *obj;
1254 IUnknown *unknown;
1255 IDirect3DRM *d3drm;
1256 HRESULT hr;
1257 int i;
1259 hr = Direct3DRMCreate(&d3drm);
1260 ok(SUCCEEDED(hr), "Test %u: Cannot get IDirect3DRM interface (hr = %x).\n", test_idx, hr);
1262 hr = IDirect3DRM_CreateObject(d3drm, clsid, NULL, iid, (void **)&unknown);
1263 ok(hr == D3DRM_OK, "Test %u: Cannot get IDirect3DRMObject interface (hr = %x).\n", test_idx, hr);
1264 hr = IUnknown_QueryInterface(unknown, &IID_IDirect3DRMObject, (void**)&obj);
1265 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1266 IUnknown_Release(unknown);
1268 context.called = 0;
1269 context.test_idx = test_idx;
1270 context.obj = obj;
1272 hr = IDirect3DRMObject_AddDestroyCallback(obj, NULL, &context);
1273 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRMERR_BADVALUE (hr = %x).\n", test_idx, hr);
1275 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1276 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1277 corder[2].callback = &destroy_callback;
1278 corder[2].context = &context;
1280 /* same callback added twice */
1281 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1282 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1283 corder[1].callback = &destroy_callback;
1284 corder[1].context = &context;
1286 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, NULL);
1287 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1289 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback1, &context);
1290 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1292 /* add one more */
1293 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback1, &context);
1294 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1295 corder[0].callback = &destroy_callback1;
1296 corder[0].context = &context;
1298 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, NULL, NULL);
1299 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected D3DRM_BADVALUE (hr = %x).\n", test_idx, hr);
1301 context.called = 0;
1302 IDirect3DRMObject_Release(obj);
1303 ok(context.called == 3, "Test %u: got %d, expected 3.\n", test_idx, context.called);
1304 for (i = 0; i < context.called; i++)
1306 ok(corder[i].callback == d3drm_corder[i].callback
1307 && corder[i].context == d3drm_corder[i].context,
1308 "Expected callback = %p, context = %p. Got callback = %p, context = %p.\n", d3drm_corder[i].callback,
1309 d3drm_corder[i].context, corder[i].callback, corder[i].context);
1312 /* test this pattern - add cb1, add cb2, add cb1, delete cb1 */
1313 hr = IDirect3DRM_CreateObject(d3drm, clsid, NULL, iid, (void **)&unknown);
1314 ok(hr == D3DRM_OK, "Test %u: Cannot get IDirect3DRMObject interface (hr = %x).\n", test_idx, hr);
1315 hr = IUnknown_QueryInterface(unknown, &IID_IDirect3DRMObject, (void**)&obj);
1316 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1317 IUnknown_Release(unknown);
1319 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1320 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1321 corder[1].callback = &destroy_callback;
1322 corder[1].context = &context;
1324 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback1, &context);
1325 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1326 corder[0].callback = &destroy_callback1;
1327 corder[0].context = &context;
1329 hr = IDirect3DRMObject_AddDestroyCallback(obj, destroy_callback, &context);
1330 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1332 hr = IDirect3DRMObject_DeleteDestroyCallback(obj, destroy_callback, &context);
1333 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1335 context.called = 0;
1336 hr = IDirect3DRMObject_QueryInterface(obj, &IID_IDirect3DRMObject, (void**)&context.obj);
1337 ok(hr == D3DRM_OK, "Test %u: expected D3DRM_OK (hr = %x).\n", test_idx, hr);
1338 IDirect3DRMObject_Release(context.obj);
1339 IUnknown_Release(unknown);
1340 ok(context.called == 2, "Test %u: got %d, expected 2.\n", test_idx, context.called);
1341 for (i = 0; i < context.called; i++)
1343 ok(corder[i].callback == d3drm_corder[i].callback
1344 && corder[i].context == d3drm_corder[i].context,
1345 "Expected callback = %p, context = %p. Got callback = %p, context = %p.\n", d3drm_corder[i].callback,
1346 d3drm_corder[i].context, corder[i].callback, corder[i].context);
1350 static void test_object(void)
1352 static const struct
1354 REFCLSID clsid;
1355 REFIID iid;
1356 BOOL todo;
1358 tests[] =
1360 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice, TRUE },
1361 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice2, TRUE },
1362 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMDevice3, TRUE },
1363 { &CLSID_CDirect3DRMDevice, &IID_IDirect3DRMWinDevice, TRUE },
1364 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture, FALSE },
1365 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture2, FALSE },
1366 { &CLSID_CDirect3DRMTexture, &IID_IDirect3DRMTexture3, FALSE },
1367 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport, TRUE },
1368 { &CLSID_CDirect3DRMViewport, &IID_IDirect3DRMViewport2, TRUE },
1370 IDirect3DRM *d3drm1;
1371 IDirect3DRM2 *d3drm2;
1372 IDirect3DRM3 *d3drm3;
1373 IUnknown *unknown = (IUnknown *)0xdeadbeef;
1374 HRESULT hr;
1375 ULONG ref1, ref2, ref3, ref4;
1376 int i;
1378 hr = Direct3DRMCreate(&d3drm1);
1379 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x).\n", hr);
1380 ref1 = get_refcount((IUnknown *)d3drm1);
1381 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1382 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
1383 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1384 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
1386 hr = IDirect3DRM_CreateObject(d3drm1, &CLSID_DirectDraw, NULL, &IID_IDirectDraw, (void **)&unknown);
1387 ok(hr == CLASSFACTORY_E_FIRST, "Expected hr == CLASSFACTORY_E_FIRST, got %#x.\n", hr);
1388 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1390 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
1392 unknown = (IUnknown *)0xdeadbeef;
1393 hr = IDirect3DRM_CreateObject(d3drm1, NULL, NULL, tests[i].iid, (void **)&unknown);
1394 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1395 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1396 unknown = (IUnknown *)0xdeadbeef;
1397 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, (void **)&unknown);
1398 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1399 ok(!unknown, "Expected object returned == NULL, got %p.\n", unknown);
1400 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, NULL, NULL);
1401 ok(hr == D3DRMERR_BADVALUE, "Test %u: expected hr == D3DRMERR_BADVALUE, got %#x.\n", i, hr);
1403 hr = IDirect3DRM_CreateObject(d3drm1, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1404 todo_wine_if(tests[i].todo)
1405 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1406 if (SUCCEEDED(hr))
1408 ref2 = get_refcount((IUnknown *)d3drm1);
1409 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1410 ref3 = get_refcount((IUnknown *)d3drm2);
1411 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1412 ref4 = get_refcount((IUnknown *)d3drm3);
1413 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1414 IUnknown_Release(unknown);
1415 ref2 = get_refcount((IUnknown *)d3drm1);
1416 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1417 ref3 = get_refcount((IUnknown *)d3drm2);
1418 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1419 ref4 = get_refcount((IUnknown *)d3drm3);
1420 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1422 /* test Add/Destroy callbacks */
1423 test_destroy_callback(i, tests[i].clsid, tests[i].iid);
1425 hr = IDirect3DRM2_CreateObject(d3drm2, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1426 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1427 ref2 = get_refcount((IUnknown *)d3drm1);
1428 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1429 ref3 = get_refcount((IUnknown *)d3drm2);
1430 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1431 ref4 = get_refcount((IUnknown *)d3drm3);
1432 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1433 IUnknown_Release(unknown);
1434 ref2 = get_refcount((IUnknown *)d3drm1);
1435 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1436 ref3 = get_refcount((IUnknown *)d3drm2);
1437 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1438 ref4 = get_refcount((IUnknown *)d3drm3);
1439 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1441 hr = IDirect3DRM3_CreateObject(d3drm3, tests[i].clsid, NULL, tests[i].iid, (void **)&unknown);
1442 ok(SUCCEEDED(hr), "Test %u: expected hr == D3DRM_OK, got %#x.\n", i, hr);
1443 ref2 = get_refcount((IUnknown *)d3drm1);
1444 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1445 ref3 = get_refcount((IUnknown *)d3drm2);
1446 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1447 ref4 = get_refcount((IUnknown *)d3drm3);
1448 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1449 IUnknown_Release(unknown);
1450 ref2 = get_refcount((IUnknown *)d3drm1);
1451 ok(ref2 == ref1, "Test %u: expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", i, ref1, ref2);
1452 ref3 = get_refcount((IUnknown *)d3drm2);
1453 ok(ref3 == ref1, "Test %u: expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", i, ref1, ref3);
1454 ref4 = get_refcount((IUnknown *)d3drm3);
1455 ok(ref4 == ref1, "Test %u: expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", i, ref1, ref4);
1459 IDirect3DRM_Release(d3drm1);
1460 IDirect3DRM2_Release(d3drm2);
1461 IDirect3DRM3_Release(d3drm3);
1464 static void test_Viewport(void)
1466 IDirectDrawClipper *pClipper;
1467 HRESULT hr;
1468 IDirect3DRM *d3drm;
1469 IDirect3DRMDevice *device;
1470 IDirect3DRMFrame *frame;
1471 IDirect3DRMViewport *viewport;
1472 IDirect3DRMViewport2 *viewport2;
1473 IDirect3DRMObject *obj, *obj2;
1474 GUID driver;
1475 HWND window;
1476 RECT rc;
1477 DWORD size, data;
1478 CHAR cname[64] = {0};
1480 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
1481 GetClientRect(window, &rc);
1483 hr = Direct3DRMCreate(&d3drm);
1484 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1486 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
1487 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
1489 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
1490 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
1492 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
1493 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
1494 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
1496 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
1497 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
1499 hr = IDirect3DRM_CreateViewport(d3drm, device, frame, rc.left, rc.top, rc.right, rc.bottom, &viewport);
1500 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMViewport interface (hr = %x)\n", hr);
1502 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMObject, (void**)&obj);
1503 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1504 ok((IDirect3DRMObject*)viewport == obj, "got object pointer %p, expected %p\n", obj, viewport);
1506 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1507 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1509 hr = IDirect3DRMViewport2_QueryInterface(viewport2, &IID_IDirect3DRMObject, (void**)&obj2);
1510 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1511 ok(obj == obj2, "got object pointer %p, expected %p\n", obj2, obj);
1512 ok((IUnknown*)viewport != (IUnknown*)viewport2, "got viewport1 %p, viewport2 %p\n", viewport, viewport2);
1514 IDirect3DRMViewport2_Release(viewport2);
1515 IDirect3DRMObject_Release(obj);
1516 IDirect3DRMObject_Release(obj2);
1518 hr = IDirect3DRMViewport_GetClassName(viewport, NULL, cname);
1519 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1520 hr = IDirect3DRMViewport_GetClassName(viewport, NULL, NULL);
1521 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1522 size = 1;
1523 hr = IDirect3DRMViewport_GetClassName(viewport, &size, cname);
1524 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1525 size = sizeof(cname);
1526 hr = IDirect3DRMViewport_GetClassName(viewport, &size, cname);
1527 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1528 ok(size == sizeof("Viewport"), "wrong size: %u\n", size);
1529 ok(!strcmp(cname, "Viewport"), "Expected cname to be \"Viewport\", but got \"%s\"\n", cname);
1531 /* AppData */
1532 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1533 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1535 hr = IDirect3DRMViewport_SetAppData(viewport, 0);
1536 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1538 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1539 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1541 hr = IDirect3DRMViewport_SetAppData(viewport, 1);
1542 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1544 hr = IDirect3DRMViewport_QueryInterface(viewport, &IID_IDirect3DRMViewport2, (void**)&viewport2);
1545 ok(hr == D3DRM_OK, "expected D3DRM_OK (hr = %x)\n", hr);
1547 data = IDirect3DRMViewport2_GetAppData(viewport2);
1548 ok(data == 1, "got %x\n", data);
1549 IDirect3DRMViewport2_Release(viewport2);
1551 IDirect3DRMFrame_Release(frame);
1552 IDirect3DRMDevice_Release(device);
1553 IDirectDrawClipper_Release(pClipper);
1555 IDirect3DRM_Release(d3drm);
1556 DestroyWindow(window);
1559 static void test_Light(void)
1561 HRESULT hr;
1562 IDirect3DRM *d3drm;
1563 IDirect3DRMLight *light;
1564 D3DRMLIGHTTYPE type;
1565 D3DCOLOR color;
1566 DWORD size;
1567 CHAR cname[64] = {0};
1569 hr = Direct3DRMCreate(&d3drm);
1570 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1572 hr = IDirect3DRM_CreateLightRGB(d3drm, D3DRMLIGHT_SPOT, 0.5, 0.5, 0.5, &light);
1573 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMLight interface (hr = %x)\n", hr);
1575 hr = IDirect3DRMLight_GetClassName(light, NULL, cname);
1576 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1577 hr = IDirect3DRMLight_GetClassName(light, NULL, NULL);
1578 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1579 size = 1;
1580 hr = IDirect3DRMLight_GetClassName(light, &size, cname);
1581 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1582 size = sizeof(cname);
1583 hr = IDirect3DRMLight_GetClassName(light, &size, cname);
1584 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1585 ok(size == sizeof("Light"), "wrong size: %u\n", size);
1586 ok(!strcmp(cname, "Light"), "Expected cname to be \"Light\", but got \"%s\"\n", cname);
1588 type = IDirect3DRMLight_GetType(light);
1589 ok(type == D3DRMLIGHT_SPOT, "wrong type (%u)\n", type);
1591 color = IDirect3DRMLight_GetColor(light);
1592 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1594 hr = IDirect3DRMLight_SetType(light, D3DRMLIGHT_POINT);
1595 ok(hr == D3DRM_OK, "Cannot set type (hr = %x)\n", hr);
1596 type = IDirect3DRMLight_GetType(light);
1597 ok(type == D3DRMLIGHT_POINT, "wrong type (%u)\n", type);
1599 hr = IDirect3DRMLight_SetColor(light, 0xff180587);
1600 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1601 color = IDirect3DRMLight_GetColor(light);
1602 ok(color == 0xff180587, "wrong color (%x)\n", color);
1604 hr = IDirect3DRMLight_SetColorRGB(light, 0.5, 0.5, 0.5);
1605 ok(hr == D3DRM_OK, "Cannot set color (hr = %x)\n", hr);
1606 color = IDirect3DRMLight_GetColor(light);
1607 ok(color == 0xff7f7f7f, "wrong color (%x)\n", color);
1609 IDirect3DRMLight_Release(light);
1611 IDirect3DRM_Release(d3drm);
1614 static void test_Material2(void)
1616 HRESULT hr;
1617 IDirect3DRM *d3drm;
1618 IDirect3DRM3 *d3drm3;
1619 IDirect3DRMMaterial2 *material2;
1620 D3DVALUE r, g, b;
1621 DWORD size;
1622 CHAR cname[64] = {0};
1624 hr = Direct3DRMCreate(&d3drm);
1625 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1627 if (FAILED(hr = IDirect3DRM_QueryInterface(d3drm, &IID_IDirect3DRM3, (void **)&d3drm3)))
1629 win_skip("Cannot get IDirect3DRM3 interface (hr = %x), skipping tests\n", hr);
1630 IDirect3DRM_Release(d3drm);
1631 return;
1634 hr = IDirect3DRM3_CreateMaterial(d3drm3, 18.5f, &material2);
1635 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMMaterial2 interface (hr = %x)\n", hr);
1637 hr = IDirect3DRMMaterial2_GetClassName(material2, NULL, cname);
1638 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1639 hr = IDirect3DRMMaterial2_GetClassName(material2, NULL, NULL);
1640 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1641 size = 1;
1642 hr = IDirect3DRMMaterial2_GetClassName(material2, &size, cname);
1643 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1644 size = sizeof(cname);
1645 hr = IDirect3DRMMaterial2_GetClassName(material2, &size, cname);
1646 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
1647 ok(size == sizeof("Material"), "wrong size: %u\n", size);
1648 ok(!strcmp(cname, "Material"), "Expected cname to be \"Material\", but got \"%s\"\n", cname);
1650 r = IDirect3DRMMaterial2_GetPower(material2);
1651 ok(r == 18.5f, "wrong power (%f)\n", r);
1653 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
1654 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1655 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);
1657 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
1658 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1659 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);
1661 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
1662 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1663 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);
1665 hr = IDirect3DRMMaterial2_SetPower(material2, 5.87f);
1666 ok(hr == D3DRM_OK, "Cannot set power (hr = %x)\n", hr);
1667 r = IDirect3DRMMaterial2_GetPower(material2);
1668 ok(r == 5.87f, "wrong power (%f)\n", r);
1670 hr = IDirect3DRMMaterial2_SetEmissive(material2, 0.5f, 0.5f, 0.5f);
1671 ok(hr == D3DRM_OK, "Cannot set emissive (hr = %x)\n", hr);
1672 hr = IDirect3DRMMaterial2_GetEmissive(material2, &r, &g, &b);
1673 ok(hr == D3DRM_OK, "Cannot get emissive (hr = %x)\n", hr);
1674 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);
1676 hr = IDirect3DRMMaterial2_SetSpecular(material2, 0.6f, 0.6f, 0.6f);
1677 ok(hr == D3DRM_OK, "Cannot set specular (hr = %x)\n", hr);
1678 hr = IDirect3DRMMaterial2_GetSpecular(material2, &r, &g, &b);
1679 ok(hr == D3DRM_OK, "Cannot get specular (hr = %x)\n", hr);
1680 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);
1682 hr = IDirect3DRMMaterial2_SetAmbient(material2, 0.7f, 0.7f, 0.7f);
1683 ok(hr == D3DRM_OK, "Cannot set ambient (hr = %x)\n", hr);
1684 hr = IDirect3DRMMaterial2_GetAmbient(material2, &r, &g, &b);
1685 ok(hr == D3DRM_OK, "Cannot get ambient (hr = %x)\n", hr);
1686 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);
1688 IDirect3DRMMaterial2_Release(material2);
1690 IDirect3DRM3_Release(d3drm3);
1691 IDirect3DRM_Release(d3drm);
1694 static void test_Texture(void)
1696 HRESULT hr;
1697 IDirect3DRM *d3drm1;
1698 IDirect3DRM2 *d3drm2;
1699 IDirect3DRM3 *d3drm3;
1700 IDirect3DRMTexture *texture1;
1701 IDirect3DRMTexture2 *texture2;
1702 IDirect3DRMTexture3 *texture3;
1704 D3DRMIMAGE initimg =
1706 2, 2, 1, 1, 32,
1707 TRUE, 2 * sizeof(DWORD), NULL, NULL,
1708 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
1710 testimg =
1712 0, 0, 0, 0, 0,
1713 TRUE, 0, (void *)0xcafebabe, NULL,
1714 0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
1716 *d3drm_img = NULL;
1718 DWORD pixel[4] = { 20000, 30000, 10000, 0 };
1719 DWORD size;
1720 CHAR cname[64] = {0};
1721 ULONG ref1, ref2, ref3, ref4;
1723 hr = Direct3DRMCreate(&d3drm1);
1724 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
1725 ref1 = get_refcount((IUnknown *)d3drm1);
1727 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
1728 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
1730 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
1731 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
1733 /* Test NULL params */
1734 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
1735 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, &texture1);
1736 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1737 ok(!texture1, "Expected texture returned == NULL, got %p.\n", texture1);
1738 hr = IDirect3DRM_CreateTexture(d3drm1, NULL, NULL);
1739 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1741 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
1742 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, &texture2);
1743 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1744 ok(!texture2, "Expected texture returned == NULL, got %p.\n", texture2);
1745 hr = IDirect3DRM2_CreateTexture(d3drm2, NULL, NULL);
1746 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1748 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
1749 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, &texture3);
1750 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1751 ok(!texture3, "Expected texture returned == NULL, got %p.\n", texture3);
1752 hr = IDirect3DRM3_CreateTexture(d3drm3, NULL, NULL);
1753 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1755 /* Tests for validation of D3DRMIMAGE struct */
1756 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
1757 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
1758 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
1759 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
1760 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
1761 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
1762 IDirect3DRMTexture_Release(texture1);
1763 IDirect3DRMTexture2_Release(texture2);
1764 IDirect3DRMTexture3_Release(texture3);
1766 testimg.rgb = 0;
1767 testimg.palette = (void *)0xdeadbeef;
1768 testimg.palette_size = 0x39;
1769 hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
1770 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
1771 hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
1772 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
1773 hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
1774 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
1775 IDirect3DRMTexture_Release(texture1);
1776 IDirect3DRMTexture2_Release(texture2);
1777 IDirect3DRMTexture3_Release(texture3);
1779 initimg.rgb = 0;
1780 texture1 = (IDirect3DRMTexture *)0xdeadbeef;
1781 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
1782 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1783 ok(!texture1, "Expected texture == NULL, got %p.\n", texture1);
1784 texture2 = (IDirect3DRMTexture2 *)0xdeadbeef;
1785 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
1786 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1787 ok(!texture2, "Expected texture == NULL, got %p.\n", texture2);
1788 texture3 = (IDirect3DRMTexture3 *)0xdeadbeef;
1789 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
1790 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1791 ok(!texture3, "Expected texture == NULL, got %p.\n", texture3);
1792 initimg.rgb = 1;
1793 initimg.red_mask = 0;
1794 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
1795 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1796 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
1797 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1798 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
1799 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1800 initimg.red_mask = 0x000000ff;
1801 initimg.green_mask = 0;
1802 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
1803 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1804 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
1805 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1806 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
1807 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1808 initimg.green_mask = 0x0000ff00;
1809 initimg.blue_mask = 0;
1810 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
1811 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1812 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
1813 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1814 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
1815 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1816 initimg.blue_mask = 0x00ff0000;
1817 initimg.buffer1 = NULL;
1818 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
1819 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1820 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
1821 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1822 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
1823 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %#x.\n", hr);
1825 initimg.buffer1 = &pixel;
1826 hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
1827 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
1828 ref2 = get_refcount((IUnknown *)d3drm1);
1829 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
1830 ref3 = get_refcount((IUnknown *)d3drm2);
1831 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
1832 ref4 = get_refcount((IUnknown *)d3drm3);
1833 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
1834 hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
1835 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
1836 ref2 = get_refcount((IUnknown *)d3drm1);
1837 ok(ref2 > ref1 + 1, "expected ref2 > (ref1 + 1), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
1838 ref3 = get_refcount((IUnknown *)d3drm2);
1839 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
1840 ref4 = get_refcount((IUnknown *)d3drm3);
1841 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
1842 hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
1843 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
1844 ref2 = get_refcount((IUnknown *)d3drm1);
1845 ok(ref2 > ref1 + 2, "expected ref2 > (ref1 + 2), got ref1 = %u , ref2 = %u.\n", ref1, ref2);
1846 ref3 = get_refcount((IUnknown *)d3drm2);
1847 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
1848 ref4 = get_refcount((IUnknown *)d3drm3);
1849 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
1851 /* Test all failures together */
1852 hr = IDirect3DRMTexture_GetClassName(texture1, NULL, cname);
1853 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1854 hr = IDirect3DRMTexture_GetClassName(texture1, NULL, NULL);
1855 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1856 hr = IDirect3DRMTexture2_GetClassName(texture2, NULL, cname);
1857 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1858 hr = IDirect3DRMTexture2_GetClassName(texture2, NULL, NULL);
1859 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1860 hr = IDirect3DRMTexture3_GetClassName(texture3, NULL, cname);
1861 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1862 hr = IDirect3DRMTexture3_GetClassName(texture3, NULL, NULL);
1863 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1864 size = 1;
1865 hr = IDirect3DRMTexture_GetClassName(texture1, &size, cname);
1866 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1867 hr = IDirect3DRMTexture2_GetClassName(texture2, &size, cname);
1868 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1869 hr = IDirect3DRMTexture3_GetClassName(texture3, &size, cname);
1870 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1871 size = sizeof("Texture") - 1;
1872 strcpy(cname, "test");
1873 hr = IDirect3DRMTexture_GetClassName(texture1, &size, cname);
1874 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1875 ok(size == sizeof("Texture") - 1, "wrong size: %u\n", size);
1876 ok(!strcmp(cname, "test"), "Expected cname to be \"test\", but got \"%s\"\n", cname);
1877 hr = IDirect3DRMTexture2_GetClassName(texture2, &size, cname);
1878 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1879 ok(size == sizeof("Texture") - 1, "wrong size: %u\n", size);
1880 ok(!strcmp(cname, "test"), "Expected cname to be \"test\", but got \"%s\"\n", cname);
1881 hr = IDirect3DRMTexture3_GetClassName(texture3, &size, cname);
1882 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
1883 ok(size == sizeof("Texture") - 1, "wrong size: %u\n", size);
1884 ok(!strcmp(cname, "test"), "Expected cname to be \"test\", but got \"%s\"\n", cname);
1886 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
1887 ok(!!d3drm_img, "Failed to get image.\n");
1888 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
1890 size = sizeof(cname);
1891 hr = IDirect3DRMTexture_GetClassName(texture1, &size, cname);
1892 ok(SUCCEEDED(hr), "Cannot get classname (hr = %x)\n", hr);
1893 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1894 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1895 size = sizeof("Texture");
1896 hr = IDirect3DRMTexture_GetClassName(texture1, &size, cname);
1897 ok(SUCCEEDED(hr), "Cannot get classname (hr = %x)\n", hr);
1898 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1899 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1901 IDirect3DRMTexture_Release(texture1);
1902 ref2 = get_refcount((IUnknown *)d3drm1);
1903 ok(ref2 - 2 == ref1, "expected (ref2 - 2) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
1904 ref3 = get_refcount((IUnknown *)d3drm2);
1905 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
1906 ref4 = get_refcount((IUnknown *)d3drm3);
1907 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1909 d3drm_img = NULL;
1910 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
1911 ok(!!d3drm_img, "Failed to get image.\n");
1912 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
1914 size = sizeof(cname);
1915 hr = IDirect3DRMTexture2_GetClassName(texture2, &size, cname);
1916 ok(SUCCEEDED(hr), "Cannot get classname (hr = %x)\n", hr);
1917 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1918 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1919 size = sizeof("Texture");
1920 hr = IDirect3DRMTexture2_GetClassName(texture2, &size, cname);
1921 ok(SUCCEEDED(hr), "Cannot get classname (hr = %x)\n", hr);
1922 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1923 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1925 IDirect3DRMTexture2_Release(texture2);
1926 ref2 = get_refcount((IUnknown *)d3drm1);
1927 ok(ref2 - 1 == ref1, "expected (ref2 - 1) == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
1928 ref3 = get_refcount((IUnknown *)d3drm2);
1929 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
1930 ref4 = get_refcount((IUnknown *)d3drm3);
1931 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1933 d3drm_img = NULL;
1934 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
1935 ok(!!d3drm_img, "Failed to get image.\n");
1936 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
1938 size = sizeof(cname);
1939 hr = IDirect3DRMTexture3_GetClassName(texture3, &size, cname);
1940 ok(SUCCEEDED(hr), "Cannot get classname (hr = %x)\n", hr);
1941 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1942 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1943 size = sizeof("Texture");
1944 hr = IDirect3DRMTexture3_GetClassName(texture3, &size, cname);
1945 ok(SUCCEEDED(hr), "Cannot get classname (hr = %x)\n", hr);
1946 ok(size == sizeof("Texture"), "wrong size: %u\n", size);
1947 ok(!strcmp(cname, "Texture"), "Expected cname to be \"Texture\", but got \"%s\"\n", cname);
1949 IDirect3DRMTexture3_Release(texture3);
1950 ref2 = get_refcount((IUnknown *)d3drm1);
1951 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
1952 ref3 = get_refcount((IUnknown *)d3drm2);
1953 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
1954 ref4 = get_refcount((IUnknown *)d3drm3);
1955 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
1957 /* InitFromImage tests */
1958 /* Tests for validation of D3DRMIMAGE struct */
1959 testimg.rgb = 1;
1960 testimg.palette = NULL;
1961 testimg.palette_size = 0;
1962 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
1963 (void **)&texture2);
1964 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
1965 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
1966 (void **)&texture3);
1967 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
1968 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
1969 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
1970 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
1971 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
1972 IDirect3DRMTexture2_Release(texture2);
1973 IDirect3DRMTexture3_Release(texture3);
1975 testimg.rgb = 0;
1976 testimg.palette = (void *)0xdeadbeef;
1977 testimg.palette_size = 0x39;
1978 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
1979 (void **)&texture2);
1980 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
1981 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
1982 (void **)&texture3);
1983 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
1984 hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
1985 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 interface (hr = %#x)\n", hr);
1986 hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
1987 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
1988 IDirect3DRMTexture2_Release(texture2);
1989 IDirect3DRMTexture3_Release(texture3);
1991 hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2,
1992 (void **)&texture2);
1993 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %#x).\n", hr);
1994 ref2 = get_refcount((IUnknown *)texture2);
1995 hr = IDirect3DRMTexture2_InitFromImage(texture2, NULL);
1996 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
1997 ref3 = get_refcount((IUnknown *)texture2);
1998 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2000 hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3,
2001 (void **)&texture3);
2002 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x).\n", hr);
2003 ref2 = get_refcount((IUnknown *)texture3);
2004 hr = IDirect3DRMTexture3_InitFromImage(texture3, NULL);
2005 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2006 ref3 = get_refcount((IUnknown *)texture3);
2007 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2009 initimg.rgb = 0;
2010 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2011 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2012 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2013 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2014 initimg.rgb = 1;
2015 initimg.red_mask = 0;
2016 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2017 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2018 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2019 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2020 initimg.red_mask = 0x000000ff;
2021 initimg.green_mask = 0;
2022 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2023 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2024 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2025 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2026 initimg.green_mask = 0x0000ff00;
2027 initimg.blue_mask = 0;
2028 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2029 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2030 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2031 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2032 initimg.blue_mask = 0x00ff0000;
2033 initimg.buffer1 = NULL;
2034 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2035 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2036 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2037 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2038 initimg.buffer1 = &pixel;
2040 d3drm_img = NULL;
2041 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2042 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 from image (hr = %#x).\n", hr);
2043 ref2 = get_refcount((IUnknown *)d3drm1);
2044 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2045 ref3 = get_refcount((IUnknown *)d3drm2);
2046 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2047 ref4 = get_refcount((IUnknown *)d3drm3);
2048 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2050 hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
2051 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2052 /* Release leaked reference to d3drm1 */
2053 IDirect3DRM_Release(d3drm1);
2055 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
2056 ok(!!d3drm_img, "Failed to get image.\n");
2057 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2058 IDirect3DRMTexture2_Release(texture2);
2059 ref2 = get_refcount((IUnknown *)d3drm1);
2060 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2061 ref3 = get_refcount((IUnknown *)d3drm2);
2062 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2063 ref4 = get_refcount((IUnknown *)d3drm3);
2064 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2066 d3drm_img = NULL;
2067 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2068 ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 from image (hr = %#x).\n", hr);
2069 ref2 = get_refcount((IUnknown *)d3drm1);
2070 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2071 ref3 = get_refcount((IUnknown *)d3drm2);
2072 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2073 ref4 = get_refcount((IUnknown *)d3drm3);
2074 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
2076 hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
2077 ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %#x.\n", hr);
2078 IDirect3DRM_Release(d3drm1);
2080 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
2081 ok(!!d3drm_img, "Failed to get image.\n");
2082 ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
2083 IDirect3DRMTexture3_Release(texture3);
2084 ref2 = get_refcount((IUnknown *)d3drm1);
2085 ok(ref2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2086 ref3 = get_refcount((IUnknown *)d3drm2);
2087 ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
2088 ref4 = get_refcount((IUnknown *)d3drm3);
2089 ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
2091 IDirect3DRM3_Release(d3drm3);
2092 IDirect3DRM2_Release(d3drm2);
2093 IDirect3DRM_Release(d3drm1);
2096 static void test_Device(void)
2098 IDirectDrawClipper *pClipper;
2099 HRESULT hr;
2100 IDirect3DRM *d3drm;
2101 IDirect3DRMDevice *device;
2102 IDirect3DRMWinDevice *win_device;
2103 GUID driver;
2104 HWND window;
2105 RECT rc;
2106 DWORD size;
2107 CHAR cname[64] = {0};
2109 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
2110 GetClientRect(window, &rc);
2112 hr = Direct3DRMCreate(&d3drm);
2113 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2115 hr = DirectDrawCreateClipper(0, &pClipper, NULL);
2116 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
2118 hr = IDirectDrawClipper_SetHWnd(pClipper, 0, window);
2119 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
2121 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
2122 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm, pClipper, &driver, rc.right, rc.bottom, &device);
2123 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
2125 hr = IDirect3DRMDevice_GetClassName(device, NULL, cname);
2126 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
2127 hr = IDirect3DRMDevice_GetClassName(device, NULL, NULL);
2128 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
2129 size = 1;
2130 hr = IDirect3DRMDevice_GetClassName(device, &size, cname);
2131 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
2132 size = sizeof(cname);
2133 hr = IDirect3DRMDevice_GetClassName(device, &size, cname);
2134 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
2135 ok(size == sizeof("Device"), "wrong size: %u\n", size);
2136 ok(!strcmp(cname, "Device"), "Expected cname to be \"Device\", but got \"%s\"\n", cname);
2138 /* WinDevice */
2139 if (FAILED(hr = IDirect3DRMDevice_QueryInterface(device, &IID_IDirect3DRMWinDevice, (void **)&win_device)))
2141 win_skip("Cannot get IDirect3DRMWinDevice interface (hr = %x), skipping tests\n", hr);
2142 goto cleanup;
2145 hr = IDirect3DRMWinDevice_GetClassName(win_device, NULL, cname);
2146 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
2147 hr = IDirect3DRMWinDevice_GetClassName(win_device, NULL, NULL);
2148 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
2149 size = 1;
2150 hr = IDirect3DRMWinDevice_GetClassName(win_device, &size, cname);
2151 ok(hr == E_INVALIDARG, "GetClassName failed with %x\n", hr);
2152 size = sizeof(cname);
2153 hr = IDirect3DRMWinDevice_GetClassName(win_device, &size, cname);
2154 ok(hr == D3DRM_OK, "Cannot get classname (hr = %x)\n", hr);
2155 ok(size == sizeof("Device"), "wrong size: %u\n", size);
2156 ok(!strcmp(cname, "Device"), "Expected cname to be \"Device\", but got \"%s\"\n", cname);
2158 IDirect3DRMWinDevice_Release(win_device);
2160 cleanup:
2161 IDirect3DRMDevice_Release(device);
2162 IDirectDrawClipper_Release(pClipper);
2164 IDirect3DRM_Release(d3drm);
2165 DestroyWindow(window);
2168 static void test_frame_transform(void)
2170 HRESULT hr;
2171 IDirect3DRM *d3drm;
2172 IDirect3DRMFrame *frame;
2173 D3DRMMATRIX4D matrix;
2175 hr = Direct3DRMCreate(&d3drm);
2176 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2178 hr = IDirect3DRM_CreateFrame(d3drm, NULL, &frame);
2179 ok(hr == D3DRM_OK, "Cannot get IDirect3DRMFrame interface (hr = %x)\n", hr);
2181 hr = IDirect3DRMFrame_GetTransform(frame, matrix);
2182 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetTransform returned hr = %x\n", hr);
2183 ok(!memcmp(matrix, identity, sizeof(D3DRMMATRIX4D)), "Returned matrix is not identity\n");
2185 IDirect3DRMFrame_Release(frame);
2186 IDirect3DRM_Release(d3drm);
2189 static int nb_objects = 0;
2190 static const GUID* refiids[] =
2192 &IID_IDirect3DRMMeshBuilder,
2193 &IID_IDirect3DRMMeshBuilder,
2194 &IID_IDirect3DRMFrame,
2195 &IID_IDirect3DRMMaterial /* Not taken into account and not notified */
2198 static void __cdecl object_load_callback(IDirect3DRMObject *object, REFIID objectguid, void *arg)
2200 ok(object != NULL, "Arg 1 should not be null\n");
2201 ok(IsEqualGUID(objectguid, refiids[nb_objects]), "Arg 2 is incorrect\n");
2202 ok(arg == (void *)0xdeadbeef, "Arg 3 should be 0xdeadbeef (got %p)\n", arg);
2203 nb_objects++;
2206 static void test_d3drm_load(void)
2208 HRESULT hr;
2209 IDirect3DRM *d3drm;
2210 D3DRMLOADMEMORY info;
2211 const GUID* req_refiids[] = { &IID_IDirect3DRMMeshBuilder, &IID_IDirect3DRMFrame, &IID_IDirect3DRMMaterial };
2213 hr = Direct3DRMCreate(&d3drm);
2214 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2216 info.lpMemory = data_d3drm_load;
2217 info.dSize = strlen(data_d3drm_load);
2218 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID **)req_refiids, 3, D3DRMLOAD_FROMMEMORY,
2219 object_load_callback, (void *)0xdeadbeef, NULL, NULL, NULL);
2220 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2221 ok(nb_objects == 3, "Should have loaded 3 objects (got %d)\n", nb_objects);
2223 IDirect3DRM_Release(d3drm);
2226 IDirect3DRMMeshBuilder *mesh_builder = NULL;
2228 static void __cdecl object_load_callback_frame(IDirect3DRMObject *object, REFIID object_guid, void *arg)
2230 HRESULT hr;
2231 IDirect3DRMFrame *frame;
2232 IDirect3DRMVisualArray *array;
2233 IDirect3DRMVisual *visual;
2234 ULONG size;
2235 char name[128];
2237 hr = IDirect3DRMObject_QueryInterface(object, &IID_IDirect3DRMFrame, (void**)&frame);
2238 ok(hr == D3DRM_OK, "IDirect3DRMObject_QueryInterface returned %x\n", hr);
2240 hr = IDirect3DRMFrame_GetVisuals(frame, &array);
2241 ok(hr == D3DRM_OK, "IDirect3DRMFrame_GetVisuals returned %x\n", hr);
2243 size = IDirect3DRMVisualArray_GetSize(array);
2244 ok(size == 1, "Wrong size %u returned, expected 1\n", size);
2246 hr = IDirect3DRMVisualArray_GetElement(array, 0, &visual);
2247 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetElement returned %x\n", hr);
2249 hr = IDirect3DRMVisual_QueryInterface(visual, &IID_IDirect3DRMMeshBuilder, (void**)&mesh_builder);
2250 ok(hr == D3DRM_OK, "IDirect3DRMVisualArray_GetSize returned %x\n", hr);
2252 size = sizeof(name);
2253 hr = IDirect3DRMMeshBuilder_GetName(mesh_builder, &size, name);
2254 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_GetName returned %x\n", hr);
2255 ok(!strcmp(name, "mesh1"), "Wrong name %s, expected mesh1\n", name);
2257 IDirect3DRMVisual_Release(visual);
2258 IDirect3DRMVisualArray_Release(array);
2259 IDirect3DRMFrame_Release(frame);
2262 struct {
2263 int vertex_count;
2264 int face_count;
2265 int vertex_per_face;
2266 int face_data_size;
2267 DWORD color;
2268 float power;
2269 float specular[3];
2270 float emissive[3];
2271 } groups[3] = {
2272 { 4, 3, 3, 9, 0x4c0000ff, 30.0f, { 0.31f, 0.32f, 0.33f }, { 0.34f, 0.35f, 0.36f } },
2273 { 4, 2, 3, 6, 0x3300ff00, 20.0f, { 0.21f, 0.22f, 0.23f }, { 0.24f, 0.25f, 0.26f } },
2274 { 3, 1, 3, 3, 0x19ff0000, 10.0f, { 0.11f, 0.12f, 0.13f }, { 0.14f, 0.15f, 0.16f } }
2277 static void test_frame_mesh_materials(void)
2279 HRESULT hr;
2280 IDirect3DRM *d3drm;
2281 D3DRMLOADMEMORY info;
2282 const GUID *req_refiids[] = { &IID_IDirect3DRMFrame };
2283 IDirect3DRMMesh *mesh;
2284 ULONG size;
2285 IDirect3DRMMaterial *material;
2286 IDirect3DRMTexture *texture;
2287 int i;
2289 hr = Direct3DRMCreate(&d3drm);
2290 ok(hr == D3DRM_OK, "Direct3DRMCreate returned %x\n", hr);
2292 info.lpMemory = data_frame_mesh_materials;
2293 info.dSize = strlen(data_frame_mesh_materials);
2294 hr = IDirect3DRM_Load(d3drm, &info, NULL, (GUID**)req_refiids, 1, D3DRMLOAD_FROMMEMORY, object_load_callback_frame, (void*)0xdeadbeef, NULL, NULL, NULL);
2295 ok(hr == D3DRM_OK, "Cannot load data (hr = %x)\n", hr);
2297 hr = IDirect3DRMMeshBuilder_CreateMesh(mesh_builder, &mesh);
2298 ok(hr == D3DRM_OK, "IDirect3DRMMeshBuilder_CreateMesh returned %x\n", hr);
2300 size = IDirect3DRMMesh_GetGroupCount(mesh);
2301 ok(size == 3, "Wrong size %u returned, expected 3\n", size);
2303 for (i = 0; i < size; i++)
2305 D3DVALUE red, green, blue, power;
2306 D3DCOLOR color;
2307 unsigned vertex_count, face_count, vertex_per_face;
2308 DWORD face_data_size;
2310 hr = IDirect3DRMMesh_GetGroup(mesh, i, &vertex_count, &face_count, &vertex_per_face, &face_data_size, NULL);
2311 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroup returned %x\n", i, hr);
2312 ok(vertex_count == groups[i].vertex_count, "Group %d: Wrong vertex count %d, expected %d\n", i, vertex_count, groups[i].vertex_count);
2313 ok(face_count == groups[i].face_count, "Group %d: Wrong face count %d; expected %d\n", i, face_count, groups[i].face_count);
2314 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);
2315 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);
2317 color = IDirect3DRMMesh_GetGroupColor(mesh, i);
2318 ok(color == groups[i].color, "Group %d: Wrong color %x, expected %x\n", i, color, groups[i].color);
2320 hr = IDirect3DRMMesh_GetGroupMaterial(mesh, i, &material);
2321 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupMaterial returned %x\n", i, hr);
2322 ok(material != NULL, "Group %d: No material\n", i);
2323 power = IDirect3DRMMaterial_GetPower(material);
2324 ok(power == groups[i].power, "Group %d: Wrong power %f, expected %f\n", i, power, groups[i].power);
2325 hr = IDirect3DRMMaterial_GetSpecular(material, &red, &green, &blue);
2326 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetSpecular returned %x\n", i, hr);
2327 ok(red == groups[i].specular[0], "Group %d: Wrong specular red %f, expected %f\n", i, red, groups[i].specular[0]);
2328 ok(green == groups[i].specular[1], "Group %d: Wrong specular green %f, pD3DRMexpected %f\n", i, green, groups[i].specular[1]);
2329 ok(blue == groups[i].specular[2], "Group %d: Wrong specular blue %f, expected %f\n", i, blue, groups[i].specular[2]);
2330 hr = IDirect3DRMMaterial_GetEmissive(material, &red, &green, &blue);
2331 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMaterial_GetEmissive returned %x\n", i, hr);
2332 ok(red == groups[i].emissive[0], "Group %d: Wrong emissive red %f, expected %f\n", i, red, groups[i].emissive[0]);
2333 ok(green == groups[i].emissive[1], "Group %d: Wrong emissive green %f, expected %f\n", i, green, groups[i].emissive[1]);
2334 ok(blue == groups[i].emissive[2], "Group %d: Wrong emissive blue %f, expected %f\n", i, blue, groups[i].emissive[2]);
2336 hr = IDirect3DRMMesh_GetGroupTexture(mesh, i, &texture);
2337 ok(hr == D3DRM_OK, "Group %d: IDirect3DRMMesh_GetGroupTexture returned %x\n", i, hr);
2338 ok(!texture, "Group %d: Unexpected texture\n", i);
2340 if (material)
2341 IDirect3DRMMaterial_Release(material);
2342 if (texture)
2343 IDirect3DRMTexture_Release(texture);
2346 IDirect3DRMMesh_Release(mesh);
2347 IDirect3DRMMeshBuilder_Release(mesh_builder);
2348 IDirect3DRM_Release(d3drm);
2351 struct qi_test
2353 REFIID iid;
2354 REFIID refcount_iid;
2355 REFIID vtable_iid;
2356 HRESULT hr;
2359 static void test_qi(const char *test_name, IUnknown *base_iface,
2360 REFIID refcount_iid, const struct qi_test *tests, UINT entry_count)
2362 ULONG refcount, expected_refcount;
2363 IUnknown *iface1, *iface2;
2364 HRESULT hr;
2365 UINT i, j;
2367 for (i = 0; i < entry_count; ++i)
2369 hr = IUnknown_QueryInterface(base_iface, tests[i].iid, (void **)&iface1);
2370 ok(hr == tests[i].hr, "Got hr %#x for test \"%s\" %u.\n", hr, test_name, i);
2371 if (SUCCEEDED(hr))
2373 for (j = 0; j < entry_count; ++j)
2375 hr = IUnknown_QueryInterface(iface1, tests[j].iid, (void **)&iface2);
2376 ok(hr == tests[j].hr, "Got hr %#x for test \"%s\" %u, %u.\n", hr, test_name, i, j);
2377 if (SUCCEEDED(hr))
2379 expected_refcount = 0;
2380 if (IsEqualGUID(refcount_iid, tests[j].refcount_iid))
2381 ++expected_refcount;
2382 if (IsEqualGUID(tests[i].refcount_iid, tests[j].refcount_iid))
2383 ++expected_refcount;
2384 refcount = IUnknown_Release(iface2);
2385 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
2386 refcount, test_name, i, j, expected_refcount);
2387 if (tests[i].vtable_iid && tests[j].vtable_iid && IsEqualGUID(tests[i].vtable_iid, tests[j].vtable_iid))
2388 ok(iface1 == iface2,
2389 "Expected iface1 == iface2 for test \"%s\" %u, %u. Got iface1 = %p, iface 2 = %p.\n",
2390 test_name, i, j, iface1, iface2);
2391 else if (tests[i].vtable_iid && tests[j].vtable_iid)
2392 ok(iface1 != iface2,
2393 "Expected iface1 != iface2 for test \"%s\" %u, %u. Got iface1 == iface2 == %p.\n",
2394 test_name, i, j, iface1);
2398 expected_refcount = 0;
2399 if (IsEqualGUID(refcount_iid, tests[i].refcount_iid))
2400 ++expected_refcount;
2401 refcount = IUnknown_Release(iface1);
2402 ok(refcount == expected_refcount, "Got refcount %u for test \"%s\" %u, expected %u.\n",
2403 refcount, test_name, i, expected_refcount);
2408 static void test_d3drm_qi(void)
2410 static const struct qi_test tests[] =
2412 { &IID_IDirect3DRM3, &IID_IDirect3DRM3, &IID_IDirect3DRM3, S_OK },
2413 { &IID_IDirect3DRM2, &IID_IDirect3DRM2, &IID_IDirect3DRM2, S_OK },
2414 { &IID_IDirect3DRM, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
2415 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2416 { &IID_IDirect3DRMObject, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2417 { &IID_IDirect3DRMObject2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2418 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2419 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2420 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2421 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2422 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2423 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2424 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2425 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2426 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2427 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2428 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2429 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2430 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2431 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2432 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2433 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2434 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2435 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2436 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2437 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2438 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2439 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2440 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2441 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2442 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2443 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2444 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2445 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2446 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2447 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2448 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2449 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2450 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2451 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2452 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2453 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2454 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2455 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2456 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2457 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2458 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2459 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2460 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2461 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2462 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2463 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2464 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2465 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2466 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2467 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2468 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2469 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2470 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2471 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2472 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2473 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2474 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2475 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2476 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2477 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2478 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2479 { &IID_IUnknown, &IID_IDirect3DRM, &IID_IDirect3DRM, S_OK },
2481 HRESULT hr;
2482 IDirect3DRM *d3drm;
2484 hr = Direct3DRMCreate(&d3drm);
2485 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2487 test_qi("d3drm_qi", (IUnknown *)d3drm, &IID_IDirect3DRM, tests, sizeof(tests) / sizeof(*tests));
2489 IDirect3DRM_Release(d3drm);
2492 static void test_frame_qi(void)
2494 static const struct qi_test tests[] =
2496 { &IID_IDirect3DRMFrame3, &IID_IUnknown, &IID_IDirect3DRMFrame3, S_OK },
2497 { &IID_IDirect3DRMFrame2, &IID_IUnknown, &IID_IDirect3DRMFrame2, S_OK },
2498 { &IID_IDirect3DRMFrame, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
2499 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2500 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2501 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
2502 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2503 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2504 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2505 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2506 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2507 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2508 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMFrame, S_OK },
2509 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2510 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2511 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2512 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2513 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2514 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2515 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2516 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2517 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2518 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2519 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2520 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2521 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2522 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2523 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2524 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2525 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2526 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2527 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2528 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2529 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2530 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2531 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2532 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2533 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2534 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2535 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2536 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2537 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2538 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2539 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2540 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2541 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2542 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2543 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2544 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2545 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2546 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2547 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2548 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2549 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2550 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2551 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2552 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2553 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2554 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2555 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2556 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2557 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2558 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2559 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2560 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2561 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2562 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK },
2564 HRESULT hr;
2565 IDirect3DRM *d3drm1;
2566 IDirect3DRM2 *d3drm2;
2567 IDirect3DRM3 *d3drm3;
2568 IDirect3DRMFrame *frame1;
2569 IDirect3DRMFrame2 *frame2;
2570 IDirect3DRMFrame3 *frame3;
2571 IUnknown *unknown;
2573 hr = Direct3DRMCreate(&d3drm1);
2574 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2576 hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1);
2577 ok(hr == D3DRM_OK, "Failed to create frame1 (hr = %x)\n", hr);
2578 hr = IDirect3DRMFrame_QueryInterface(frame1, &IID_IUnknown, (void **)&unknown);
2579 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame1 (hr = %x)\n", hr);
2580 IDirect3DRMFrame_Release(frame1);
2581 test_qi("frame1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2582 IUnknown_Release(unknown);
2584 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2585 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2586 hr = IDirect3DRM2_CreateFrame(d3drm2, NULL, &frame2);
2587 ok(hr == D3DRM_OK, "Failed to create frame2 (hr = %x)\n", hr);
2588 hr = IDirect3DRMFrame2_QueryInterface(frame2, &IID_IUnknown, (void **)&unknown);
2589 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame2 (hr = %x)\n", hr);
2590 IDirect3DRMFrame2_Release(frame2);
2591 test_qi("frame2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2592 IUnknown_Release(unknown);
2594 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2595 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2596 hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3);
2597 ok(hr == D3DRM_OK, "Failed to create frame3 (hr = %x)\n", hr);
2598 hr = IDirect3DRMFrame3_QueryInterface(frame3, &IID_IUnknown, (void **)&unknown);
2599 ok(hr == D3DRM_OK, "Failed to create IUnknown from frame3 (hr = %x)\n", hr);
2600 IDirect3DRMFrame3_Release(frame3);
2601 test_qi("frame3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2602 IUnknown_Release(unknown);
2604 IDirect3DRM3_Release(d3drm3);
2605 IDirect3DRM2_Release(d3drm2);
2606 IDirect3DRM_Release(d3drm1);
2609 static void test_device_qi(void)
2611 static const struct qi_test tests[] =
2613 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2614 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2615 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2616 { &IID_IDirect3DRMDevice, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
2617 { &IID_IDirect3DRMDevice2, &IID_IUnknown, &IID_IDirect3DRMDevice2, S_OK, },
2618 { &IID_IDirect3DRMDevice3, &IID_IUnknown, &IID_IDirect3DRMDevice3, S_OK, },
2619 { &IID_IDirect3DRMWinDevice, &IID_IUnknown, &IID_IDirect3DRMWinDevice, S_OK, },
2620 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMDevice, S_OK, },
2621 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2622 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2623 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2624 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2625 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2626 { &IID_IDirect3DRMVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2627 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2628 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2629 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2630 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2631 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2632 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2633 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2634 { &IID_IDirect3DRMTexture, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2635 { &IID_IDirect3DRMTexture2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2636 { &IID_IDirect3DRMTexture3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2637 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2638 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2639 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2640 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2641 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2642 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2643 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2644 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2645 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2646 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2647 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2648 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2649 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2650 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2651 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2652 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2653 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2654 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2655 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2656 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2657 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2658 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2659 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2660 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2661 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2662 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2663 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2664 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2665 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2666 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2667 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2668 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2669 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2670 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2671 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2672 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2673 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2674 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2675 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2676 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2677 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2678 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2679 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
2680 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
2682 HRESULT hr;
2683 IDirect3DRM *d3drm1;
2684 IDirect3DRM2 *d3drm2;
2685 IDirect3DRM3 *d3drm3;
2686 IDirectDrawClipper *clipper;
2687 IDirect3DRMDevice *device1;
2688 IDirect3DRMDevice2 *device2;
2689 IDirect3DRMDevice3 *device3;
2690 IUnknown *unknown;
2691 HWND window;
2692 GUID driver;
2693 RECT rc;
2695 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
2696 GetClientRect(window, &rc);
2697 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2698 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x)\n", hr);
2699 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2700 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x)\n", hr);
2702 hr = Direct3DRMCreate(&d3drm1);
2703 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
2704 memcpy(&driver, &IID_IDirect3DRGBDevice, sizeof(GUID));
2705 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
2706 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice interface (hr = %x)\n", hr);
2707 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IUnknown, (void **)&unknown);
2708 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice (hr = %x)\n", hr);
2709 IDirect3DRMDevice_Release(device1);
2710 test_qi("device1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2711 IUnknown_Release(unknown);
2713 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2714 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2715 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
2716 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 interface (hr = %x)\n", hr);
2717 hr = IDirect3DRMDevice2_QueryInterface(device2, &IID_IUnknown, (void **)&unknown);
2718 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice2 (hr = %x)\n", hr);
2719 IDirect3DRMDevice2_Release(device2);
2720 test_qi("device2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2721 IUnknown_Release(unknown);
2723 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
2724 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
2725 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
2726 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice3 interface (hr = %x)\n", hr);
2727 IDirect3DRMDevice3_QueryInterface(device3, &IID_IUnknown, (void **)&unknown);
2728 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMDevice3 (hr = %x)\n", hr);
2729 IDirect3DRMDevice3_Release(device3);
2730 test_qi("device3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
2731 IUnknown_Release(unknown);
2733 IDirectDrawClipper_Release(clipper);
2734 IDirect3DRM3_Release(d3drm3);
2735 IDirect3DRM2_Release(d3drm2);
2736 IDirect3DRM_Release(d3drm1);
2737 DestroyWindow(window);
2741 static HRESULT CALLBACK surface_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
2743 IDirectDrawSurface **primary = context;
2745 if (desc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
2747 *primary = surface;
2748 return DDENUMRET_CANCEL;
2750 IDirectDrawSurface_Release(surface);
2752 return DDENUMRET_OK;
2755 static void test_create_device_from_clipper1(void)
2757 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2758 IDirect3DRM *d3drm1 = NULL;
2759 IDirectDraw *ddraw = NULL;
2760 IUnknown *unknown = NULL;
2761 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
2762 IDirect3DDevice *d3ddevice1 = NULL;
2763 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
2764 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
2765 IDirectDrawSurface7 *surface7 = NULL;
2766 DDSURFACEDESC desc, surface_desc;
2767 DWORD expected_flags;
2768 HWND window;
2769 GUID driver = IID_IDirect3DRGBDevice;
2770 HRESULT hr;
2771 ULONG ref1, ref2, cref1, cref2;
2772 RECT rc;
2774 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
2775 GetClientRect(window, &rc);
2776 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2777 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
2778 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2779 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
2781 hr = Direct3DRMCreate(&d3drm1);
2782 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2783 ref1 = get_refcount((IUnknown *)d3drm1);
2784 cref1 = get_refcount((IUnknown *)clipper);
2786 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 0, 0, &device1);
2787 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2788 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
2790 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2791 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, NULL, &driver, 300, 200, &device1);
2792 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2794 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, NULL);
2795 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2797 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, 300, 200, &device1);
2798 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2799 ref2 = get_refcount((IUnknown *)d3drm1);
2800 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
2801 cref2 = get_refcount((IUnknown *)clipper);
2802 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
2804 /* Fetch immediate mode device in order to access render target */
2805 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
2806 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2808 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
2809 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2811 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
2812 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
2814 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2815 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
2816 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
2817 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
2818 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
2819 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2820 IUnknown_Release(unknown);
2821 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2822 NULL, &d3drm_primary, surface_callback);
2823 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2824 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
2825 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
2826 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
2827 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
2829 IDirectDrawClipper_Release(d3drm_clipper);
2830 IDirectDrawSurface_Release(d3drm_primary);
2831 IDirectDrawSurface7_Release(surface7);
2832 IDirectDraw_Release(ddraw);
2834 /* Check properties of render target and depth surface */
2835 surface_desc.dwSize = sizeof(surface_desc);
2836 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2837 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2839 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2840 surface_desc.dwWidth, surface_desc.dwHeight);
2841 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
2842 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
2843 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2844 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
2846 hr = DirectDrawCreate(NULL, &ddraw, NULL);
2847 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2848 desc.dwSize = sizeof(desc);
2849 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2850 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2851 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
2852 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
2854 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
2855 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
2857 desc.dwSize = sizeof(desc);
2858 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
2859 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
2861 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
2862 desc.dwWidth, desc.dwHeight);
2863 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
2864 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
2865 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
2866 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
2867 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
2869 /* Release old objects and check refcount of device and clipper */
2870 IDirectDrawSurface_Release(ds);
2871 ds = NULL;
2872 IDirectDrawSurface_Release(surface);
2873 surface = NULL;
2874 IDirect3DDevice_Release(d3ddevice1);
2875 d3ddevice1 = NULL;
2876 IDirect3DRMDevice_Release(device1);
2877 ref2 = get_refcount((IUnknown *)d3drm1);
2878 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
2879 cref2 = get_refcount((IUnknown *)clipper);
2880 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
2882 /* Test if render target format follows the screen format */
2883 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2884 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2885 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
2886 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
2888 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
2889 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
2890 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
2892 hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1);
2893 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
2895 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
2896 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
2898 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
2899 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2901 surface_desc.dwSize = sizeof(surface_desc);
2902 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
2903 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
2904 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
2905 surface_desc.ddpfPixelFormat.dwRGBBitCount);
2907 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
2908 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
2910 if (ds)
2911 IDirectDrawSurface_Release(ds);
2912 IDirectDrawSurface_Release(surface);
2913 IDirect3DDevice_Release(d3ddevice1);
2914 IDirect3DRMDevice_Release(device1);
2915 IDirect3DRM_Release(d3drm1);
2916 IDirectDrawClipper_Release(clipper);
2917 IDirectDraw_Release(ddraw);
2918 DestroyWindow(window);
2921 static void test_create_device_from_clipper2(void)
2923 DDSCAPS caps = { DDSCAPS_ZBUFFER };
2924 IDirect3DRM *d3drm1 = NULL;
2925 IDirect3DRM2 *d3drm2 = NULL;
2926 IDirectDraw *ddraw = NULL;
2927 IUnknown *unknown = NULL;
2928 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
2929 IDirect3DDevice2 *d3ddevice2 = NULL;
2930 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
2931 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
2932 IDirectDrawSurface7 *surface7 = NULL;
2933 DDSURFACEDESC desc, surface_desc;
2934 DWORD expected_flags;
2935 HWND window;
2936 GUID driver = IID_IDirect3DRGBDevice;
2937 HRESULT hr;
2938 ULONG ref1, ref2, ref3, cref1, cref2;
2939 RECT rc;
2941 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
2942 GetClientRect(window, &rc);
2943 hr = DirectDrawCreateClipper(0, &clipper, NULL);
2944 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
2945 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
2946 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
2948 hr = Direct3DRMCreate(&d3drm1);
2949 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
2950 ref1 = get_refcount((IUnknown *)d3drm1);
2951 cref1 = get_refcount((IUnknown *)clipper);
2953 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
2954 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
2955 ref2 = get_refcount((IUnknown *)d3drm2);
2957 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 0, 0, &device2);
2958 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2959 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
2961 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
2962 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, NULL, &driver, 300, 200, &device2);
2963 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2965 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, NULL);
2966 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
2968 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, 300, 200, &device2);
2969 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
2970 ref3 = get_refcount((IUnknown *)d3drm1);
2971 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
2972 ref3 = get_refcount((IUnknown *)d3drm2);
2973 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
2974 cref2 = get_refcount((IUnknown *)clipper);
2975 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
2977 /* Fetch immediate mode device in order to access render target */
2978 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
2979 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
2981 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
2982 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
2984 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
2985 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
2987 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
2988 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
2989 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
2990 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
2991 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
2992 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
2993 IUnknown_Release(unknown);
2994 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
2995 NULL, &d3drm_primary, surface_callback);
2996 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
2997 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
2998 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
2999 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3000 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3002 IDirectDrawClipper_Release(d3drm_clipper);
3003 IDirectDrawSurface_Release(d3drm_primary);
3004 IDirectDrawSurface7_Release(surface7);
3005 IDirectDraw_Release(ddraw);
3007 /* Check properties of render target and depth surface */
3008 surface_desc.dwSize = sizeof(surface_desc);
3009 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3010 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3012 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3013 surface_desc.dwWidth, surface_desc.dwHeight);
3014 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3015 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3016 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3017 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3019 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3020 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3021 desc.dwSize = sizeof(desc);
3022 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3023 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3024 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3025 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3027 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3028 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3030 desc.dwSize = sizeof(desc);
3031 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3032 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3034 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3035 desc.dwWidth, desc.dwHeight);
3036 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3037 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3038 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3039 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3040 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3042 /* Release old objects and check refcount of device and clipper */
3043 IDirectDrawSurface_Release(ds);
3044 ds = NULL;
3045 IDirectDrawSurface_Release(surface);
3046 surface = NULL;
3047 IDirect3DDevice2_Release(d3ddevice2);
3048 d3ddevice2 = NULL;
3049 IDirect3DRMDevice2_Release(device2);
3050 ref3 = get_refcount((IUnknown *)d3drm1);
3051 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3052 ref3 = get_refcount((IUnknown *)d3drm2);
3053 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3054 cref2 = get_refcount((IUnknown *)clipper);
3055 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3057 /* Test if render target format follows the screen format */
3058 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3059 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3060 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3061 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3063 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3064 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3065 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3067 hr = IDirect3DRM2_CreateDeviceFromClipper(d3drm2, clipper, &driver, rc.right, rc.bottom, &device2);
3068 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3070 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3071 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3073 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3074 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3076 surface_desc.dwSize = sizeof(surface_desc);
3077 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3078 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3079 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3080 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3082 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3083 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3085 IDirectDrawSurface_Release(surface);
3086 IDirect3DDevice2_Release(d3ddevice2);
3087 IDirect3DRMDevice2_Release(device2);
3088 IDirect3DRM2_Release(d3drm2);
3089 IDirect3DRM_Release(d3drm1);
3090 IDirectDrawClipper_Release(clipper);
3091 IDirectDraw_Release(ddraw);
3092 DestroyWindow(window);
3095 static void test_create_device_from_clipper3(void)
3097 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3098 IDirect3DRM *d3drm1 = NULL;
3099 IDirect3DRM3 *d3drm3 = NULL;
3100 IDirectDraw *ddraw = NULL;
3101 IUnknown *unknown = NULL;
3102 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
3103 IDirect3DDevice2 *d3ddevice2 = NULL;
3104 IDirectDrawClipper *clipper = NULL, *d3drm_clipper = NULL;
3105 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_primary = NULL;
3106 IDirectDrawSurface7 *surface7 = NULL;
3107 DDSURFACEDESC desc, surface_desc;
3108 DWORD expected_flags;
3109 HWND window;
3110 GUID driver = IID_IDirect3DRGBDevice;
3111 HRESULT hr;
3112 ULONG ref1, ref2, ref3, cref1, cref2;
3113 RECT rc;
3115 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 500, 400, 0, 0, 0, 0);
3116 GetClientRect(window, &rc);
3117 hr = DirectDrawCreateClipper(0, &clipper, NULL);
3118 ok(hr == DD_OK, "Cannot get IDirectDrawClipper interface (hr = %x).\n", hr);
3119 hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
3120 ok(hr == DD_OK, "Cannot set HWnd to Clipper (hr = %x).\n", hr);
3122 hr = Direct3DRMCreate(&d3drm1);
3123 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3124 ref1 = get_refcount((IUnknown *)d3drm1);
3125 cref1 = get_refcount((IUnknown *)clipper);
3127 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3128 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3129 ref2 = get_refcount((IUnknown *)d3drm3);
3131 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 0, 0, &device3);
3132 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3133 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
3135 /* If NULL is passed for clipper, CreateDeviceFromClipper returns D3DRMERR_BADVALUE */
3136 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, NULL, &driver, 300, 200, &device3);
3137 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3139 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, NULL);
3140 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3142 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, 300, 200, &device3);
3143 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3144 ref3 = get_refcount((IUnknown *)d3drm1);
3145 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3146 ref3 = get_refcount((IUnknown *)d3drm3);
3147 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3148 cref2 = get_refcount((IUnknown *)clipper);
3149 ok(cref2 > cref1, "expected cref2 > cref1, got cref1 = %u , cref2 = %u.\n", cref1, cref2);
3151 /* Fetch immediate mode device in order to access render target */
3152 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3153 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3155 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3156 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3158 hr = IDirectDrawSurface_GetClipper(surface, &d3drm_clipper);
3159 ok(hr == DDERR_NOCLIPPERATTACHED, "Expected hr == DDERR_NOCLIPPERATTACHED, got %x.\n", hr);
3161 /* Check if CreateDeviceFromClipper creates a primary surface and attaches the clipper to it */
3162 hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirectDrawSurface7, (void **)&surface7);
3163 ok(hr == DD_OK, "Cannot get IDirectDrawSurface7 interface (hr = %x).\n", hr);
3164 IDirectDrawSurface7_GetDDInterface(surface7, (void **)&unknown);
3165 hr = IUnknown_QueryInterface(unknown, &IID_IDirectDraw, (void **)&ddraw);
3166 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3167 IUnknown_Release(unknown);
3168 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3169 NULL, &d3drm_primary, surface_callback);
3170 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3171 ok(d3drm_primary != NULL, "No primary surface was enumerated.\n");
3172 hr = IDirectDrawSurface_GetClipper(d3drm_primary, &d3drm_clipper);
3173 ok(hr == DD_OK, "Cannot get attached clipper from primary surface (hr = %x).\n", hr);
3174 ok(d3drm_clipper == clipper, "Expected clipper returned == %p, got %p.\n", clipper , d3drm_clipper);
3176 IDirectDrawClipper_Release(d3drm_clipper);
3177 IDirectDrawSurface_Release(d3drm_primary);
3178 IDirectDrawSurface7_Release(surface7);
3179 IDirectDraw_Release(ddraw);
3181 /* Check properties of render target and depth surface */
3182 surface_desc.dwSize = sizeof(surface_desc);
3183 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3184 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3186 ok((surface_desc.dwWidth == 300) && (surface_desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3187 surface_desc.dwWidth, surface_desc.dwHeight);
3188 ok((surface_desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
3189 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, surface_desc.ddsCaps.dwCaps);
3190 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3191 ok(surface_desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, surface_desc.dwFlags);
3193 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3194 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3195 desc.dwSize = sizeof(desc);
3196 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3197 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3198 ok(desc.ddpfPixelFormat.dwRGBBitCount == surface_desc.ddpfPixelFormat.dwRGBBitCount, "Expected %u bpp, got %u bpp.\n",
3199 surface_desc.ddpfPixelFormat.dwRGBBitCount, desc.ddpfPixelFormat.dwRGBBitCount);
3201 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3202 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3204 desc.dwSize = sizeof(desc);
3205 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3206 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3208 ok((desc.dwWidth == 300) && (desc.dwHeight == 200), "Expected surface dimensions = 300, 200, got %u, %u.\n",
3209 desc.dwWidth, desc.dwHeight);
3210 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3211 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3212 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3213 ok(desc.dwZBufferBitDepth == 16, "Expected 16 for Z buffer bit depth, got %u.\n", desc.dwZBufferBitDepth);
3214 ok(desc.ddpfPixelFormat.dwStencilBitMask == 0, "Expected 0 stencil bits, got %x.\n", desc.ddpfPixelFormat.dwStencilBitMask);
3216 /* Release old objects and check refcount of device and clipper */
3217 IDirectDrawSurface_Release(ds);
3218 ds = NULL;
3219 IDirectDrawSurface_Release(surface);
3220 surface = NULL;
3221 IDirect3DDevice2_Release(d3ddevice2);
3222 d3ddevice2 = NULL;
3223 IDirect3DRMDevice3_Release(device3);
3224 ref3 = get_refcount((IUnknown *)d3drm1);
3225 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3226 ref3 = get_refcount((IUnknown *)d3drm3);
3227 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3228 cref2 = get_refcount((IUnknown *)clipper);
3229 ok(cref1 == cref2, "expected cref1 == cref2, got cref1 = %u, cref2 = %u.\n", cref1, cref2);
3231 /* Test if render target format follows the screen format */
3232 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3233 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3234 hr = IDirectDraw_SetDisplayMode(ddraw, desc.dwWidth, desc.dwHeight, 16);
3235 ok(hr == DD_OK, "Cannot set display mode to 16bpp (hr = %x).\n", hr);
3237 hr = IDirectDraw_GetDisplayMode(ddraw, &desc);
3238 ok(hr == DD_OK, "Cannot get IDirectDraw display mode (hr = %x)\n", hr);
3239 ok(desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16 bpp, got %u.\n", desc.ddpfPixelFormat.dwRGBBitCount);
3241 hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3);
3242 ok(hr == D3DRM_OK, "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3244 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3245 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3247 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &surface);
3248 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3250 surface_desc.dwSize = sizeof(surface_desc);
3251 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &surface_desc);
3252 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3253 todo_wine ok(surface_desc.ddpfPixelFormat.dwRGBBitCount == 16, "Expected 16bpp, got %ubpp.\n",
3254 surface_desc.ddpfPixelFormat.dwRGBBitCount);
3256 hr = IDirectDraw2_RestoreDisplayMode(ddraw);
3257 ok(SUCCEEDED(hr), "RestoreDisplayMode failed, hr %#x.\n", hr);
3259 IDirectDrawSurface_Release(surface);
3260 IDirect3DDevice2_Release(d3ddevice2);
3261 IDirect3DRMDevice3_Release(device3);
3262 IDirect3DRM3_Release(d3drm3);
3263 IDirect3DRM_Release(d3drm1);
3264 IDirectDrawClipper_Release(clipper);
3265 IDirectDraw_Release(ddraw);
3266 DestroyWindow(window);
3269 static void test_create_device_from_surface1(void)
3271 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3272 DDSURFACEDESC desc;
3273 IDirectDraw *ddraw = NULL;
3274 IDirect3DRM *d3drm1 = NULL;
3275 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3276 IDirect3DDevice *d3ddevice1 = NULL;
3277 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3278 DWORD expected_flags;
3279 HWND window;
3280 GUID driver = IID_IDirect3DRGBDevice;
3281 ULONG ref1, ref2, surface_ref1, surface_ref2;
3282 RECT rc;
3283 BOOL use_sysmem_zbuffer = FALSE;
3284 HRESULT hr;
3286 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3287 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3289 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
3290 GetClientRect(window, &rc);
3292 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3293 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3295 hr = Direct3DRMCreate(&d3drm1);
3296 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3297 ref1 = get_refcount((IUnknown *)d3drm1);
3299 /* Create a surface and use it to create the retained mode device. */
3300 memset(&desc, 0, sizeof(desc));
3301 desc.dwSize = sizeof(desc);
3302 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3303 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3304 desc.dwWidth = rc.right;
3305 desc.dwHeight = rc.bottom;
3307 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3308 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3310 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3311 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3312 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3313 IDirectDrawSurface_Release(surface);
3315 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3316 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3317 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3318 surface_ref1 = get_refcount((IUnknown *)surface);
3320 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, NULL);
3321 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
3322 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, NULL, &device1);
3323 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3324 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, NULL, surface, &device1);
3325 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3327 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3328 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3329 ref2 = get_refcount((IUnknown *)d3drm1);
3330 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3331 surface_ref2 = get_refcount((IUnknown *)surface);
3332 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
3334 /* Check if CreateDeviceFromSurface creates a primary surface */
3335 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3336 NULL, &d3drm_surface, surface_callback);
3337 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3338 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
3340 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3ddevice1);
3341 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3343 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3344 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3345 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3347 /* Check properties of attached depth surface */
3348 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
3349 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3351 memset(&desc, 0, sizeof(desc));
3352 desc.dwSize = sizeof(desc);
3353 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3354 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3356 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
3357 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3358 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3359 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3360 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3361 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3363 IDirectDrawSurface_Release(ds);
3364 IDirect3DDevice_Release(d3ddevice1);
3365 IDirectDrawSurface_Release(d3drm_surface);
3367 IDirect3DRMDevice_Release(device1);
3368 ref2 = get_refcount((IUnknown *)d3drm1);
3369 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
3370 surface_ref2 = get_refcount((IUnknown *)surface);
3371 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
3372 surface_ref1, surface_ref2);
3373 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3374 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3375 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3376 ref1 = IDirectDrawSurface_Release(ds);
3377 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3378 ref1 = IDirectDrawSurface_Release(surface);
3379 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3381 memset(&desc, 0, sizeof(desc));
3382 desc.dwSize = sizeof(desc);
3383 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3384 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3385 desc.dwWidth = rc.right;
3386 desc.dwHeight = rc.bottom;
3388 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3389 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3391 memset(&desc, 0, sizeof(desc));
3392 desc.dwSize = sizeof(desc);
3393 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3394 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
3395 desc.dwZBufferBitDepth = 16;
3396 desc.dwWidth = rc.right;
3397 desc.dwHeight = rc.bottom;
3398 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
3399 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
3400 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
3401 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3403 hr = IDirect3DRM_CreateDeviceFromSurface(d3drm1, &driver, ddraw, surface, &device1);
3404 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice interface (hr = %x).\n", hr);
3406 hr = IDirect3DRMDevice2_GetDirect3DDevice(device1, &d3ddevice1);
3407 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3409 hr = IDirect3DDevice_QueryInterface(d3ddevice1, &IID_IDirectDrawSurface, (void **)&d3drm_surface);
3410 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3411 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3413 /* Check if depth surface matches the one we created */
3414 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3415 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3416 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3418 IDirectDrawSurface_Release(d3drm_ds);
3419 IDirectDrawSurface_Release(d3drm_surface);
3420 IDirectDrawSurface_Release(ds);
3422 IDirect3DDevice_Release(d3ddevice1);
3423 IDirect3DRMDevice_Release(device1);
3424 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3425 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3426 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3427 ref1 = IDirectDrawSurface_Release(ds);
3428 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3429 ref1 = IDirectDrawSurface_Release(surface);
3430 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3431 IDirect3DRM_Release(d3drm1);
3432 IDirectDraw_Release(ddraw);
3433 DestroyWindow(window);
3436 static void test_create_device_from_surface2(void)
3438 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3439 DDSURFACEDESC desc;
3440 IDirectDraw *ddraw = NULL;
3441 IDirect3DRM *d3drm1 = NULL;
3442 IDirect3DRM2 *d3drm2 = NULL;
3443 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
3444 IDirect3DDevice2 *d3ddevice2 = NULL;
3445 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3446 DWORD expected_flags;
3447 HWND window;
3448 GUID driver = IID_IDirect3DRGBDevice;
3449 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
3450 RECT rc;
3451 BOOL use_sysmem_zbuffer = FALSE;
3452 HRESULT hr;
3454 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3455 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3457 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
3458 GetClientRect(window, &rc);
3460 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3461 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3463 hr = Direct3DRMCreate(&d3drm1);
3464 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3465 ref1 = get_refcount((IUnknown *)d3drm1);
3467 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
3468 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
3469 ref2 = get_refcount((IUnknown *)d3drm2);
3471 /* Create a surface and use it to create the retained mode device. */
3472 memset(&desc, 0, sizeof(desc));
3473 desc.dwSize = sizeof(desc);
3474 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3475 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3476 desc.dwWidth = rc.right;
3477 desc.dwHeight = rc.bottom;
3479 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3480 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3482 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
3483 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3484 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
3485 IDirectDrawSurface_Release(surface);
3487 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3488 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3489 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3490 surface_ref1 = get_refcount((IUnknown *)surface);
3492 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, NULL);
3493 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
3494 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, NULL, &device2);
3495 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3496 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, NULL, surface, &device2);
3497 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3499 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
3500 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3501 ref3 = get_refcount((IUnknown *)d3drm1);
3502 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3503 ref3 = get_refcount((IUnknown *)d3drm2);
3504 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3505 surface_ref2 = get_refcount((IUnknown *)surface);
3506 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
3508 /* Check if CreateDeviceFromSurface creates a primary surface */
3509 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3510 NULL, &d3drm_surface, surface_callback);
3511 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3512 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
3514 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3515 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3517 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3518 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3519 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3521 /* Check properties of attached depth surface */
3522 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
3523 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3525 memset(&desc, 0, sizeof(desc));
3526 desc.dwSize = sizeof(desc);
3527 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3528 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3530 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
3531 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3532 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3533 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3534 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3535 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3537 IDirectDrawSurface_Release(ds);
3538 IDirect3DDevice2_Release(d3ddevice2);
3539 IDirectDrawSurface_Release(d3drm_surface);
3541 IDirect3DRMDevice2_Release(device2);
3542 ref3 = get_refcount((IUnknown *)d3drm1);
3543 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3544 ref3 = get_refcount((IUnknown *)d3drm2);
3545 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3546 surface_ref2 = get_refcount((IUnknown *)surface);
3547 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
3548 surface_ref1, surface_ref2);
3549 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3550 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3551 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3552 ref1 = IDirectDrawSurface_Release(ds);
3553 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3555 ref1 = IDirectDrawSurface_Release(surface);
3556 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3558 memset(&desc, 0, sizeof(desc));
3559 desc.dwSize = sizeof(desc);
3560 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3561 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3562 desc.dwWidth = rc.right;
3563 desc.dwHeight = rc.bottom;
3565 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3566 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3568 memset(&desc, 0, sizeof(desc));
3569 desc.dwSize = sizeof(desc);
3570 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3571 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
3572 desc.dwZBufferBitDepth = 16;
3573 desc.dwWidth = rc.right;
3574 desc.dwHeight = rc.bottom;
3575 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
3576 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
3577 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
3578 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3580 hr = IDirect3DRM2_CreateDeviceFromSurface(d3drm2, &driver, ddraw, surface, &device2);
3581 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice2 interface (hr = %x).\n", hr);
3583 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3584 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3586 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3587 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3588 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3590 /* Check if depth surface matches the one we created */
3591 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3592 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3593 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3595 IDirectDrawSurface_Release(d3drm_ds);
3596 IDirectDrawSurface_Release(d3drm_surface);
3597 IDirectDrawSurface_Release(ds);
3599 IDirect3DDevice2_Release(d3ddevice2);
3600 IDirect3DRMDevice2_Release(device2);
3601 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3602 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3603 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3604 ref1 = IDirectDrawSurface_Release(ds);
3605 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3606 ref1 = IDirectDrawSurface_Release(surface);
3607 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3608 IDirect3DRM2_Release(d3drm2);
3609 IDirect3DRM_Release(d3drm1);
3610 IDirectDraw_Release(ddraw);
3611 DestroyWindow(window);
3614 static void test_create_device_from_surface3(void)
3616 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3617 DDSURFACEDESC desc;
3618 IDirectDraw *ddraw = NULL;
3619 IDirect3DRM *d3drm1 = NULL;
3620 IDirect3DRM3 *d3drm3 = NULL;
3621 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
3622 IDirect3DDevice2 *d3ddevice2 = NULL;
3623 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_surface = NULL, *d3drm_ds = NULL;
3624 DWORD expected_flags;
3625 HWND window;
3626 GUID driver = IID_IDirect3DRGBDevice;
3627 ULONG ref1, ref2, ref3, surface_ref1, surface_ref2;
3628 RECT rc;
3629 BOOL use_sysmem_zbuffer = FALSE;
3630 HRESULT hr;
3632 hr = DirectDrawCreate(NULL, &ddraw, NULL);
3633 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3635 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
3636 GetClientRect(window, &rc);
3638 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3639 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3641 hr = Direct3DRMCreate(&d3drm1);
3642 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3643 ref1 = get_refcount((IUnknown *)d3drm1);
3645 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
3646 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
3647 ref2 = get_refcount((IUnknown *)d3drm3);
3649 /* Create a surface and use it to create the retained mode device. */
3650 memset(&desc, 0, sizeof(desc));
3651 desc.dwSize = sizeof(desc);
3652 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3653 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
3654 desc.dwWidth = rc.right;
3655 desc.dwHeight = rc.bottom;
3657 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3658 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3660 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
3661 ok(hr == DDERR_INVALIDCAPS, "Expected hr == DDERR_INVALIDCAPS, got %x.\n", hr);
3662 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
3663 IDirectDrawSurface_Release(surface);
3665 desc.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE;
3666 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3667 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3668 surface_ref1 = get_refcount((IUnknown *)surface);
3670 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, NULL);
3671 ok(hr == D3DRMERR_BADVALUE, "Expected hr == DDERR_BADVALUE, got %x.\n", hr);
3672 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, NULL, 0, &device3);
3673 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3674 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, NULL, surface, 0, &device3);
3675 ok(hr == D3DRMERR_BADDEVICE, "Expected hr == DDERR_BADDEVICE, got %x.\n", hr);
3677 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
3678 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3679 ref3 = get_refcount((IUnknown *)d3drm1);
3680 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
3681 ref3 = get_refcount((IUnknown *)d3drm3);
3682 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3683 surface_ref2 = get_refcount((IUnknown *)surface);
3684 ok(surface_ref2 > surface_ref1, "Expected surface_ref2 > surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n", surface_ref1, surface_ref2);
3686 /* Check if CreateDeviceFromSurface creates a primary surface */
3687 hr = IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3688 NULL, &d3drm_surface, surface_callback);
3689 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3690 ok(d3drm_surface == NULL, "No primary surface should have enumerated (%p).\n", d3drm_surface);
3692 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3693 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3695 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3696 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3697 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3699 /* Check properties of attached depth surface */
3700 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &ds);
3701 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3703 memset(&desc, 0, sizeof(desc));
3704 desc.dwSize = sizeof(desc);
3705 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
3706 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
3708 use_sysmem_zbuffer = desc.ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY;
3709 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3710 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3711 ok(desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
3712 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
3713 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
3715 IDirectDrawSurface_Release(ds);
3716 IDirect3DDevice2_Release(d3ddevice2);
3717 IDirectDrawSurface_Release(d3drm_surface);
3718 IDirect3DRMDevice3_Release(device3);
3720 ref3 = get_refcount((IUnknown *)d3drm1);
3721 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
3722 ref3 = get_refcount((IUnknown *)d3drm3);
3723 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
3724 surface_ref2 = get_refcount((IUnknown *)surface);
3725 ok(surface_ref2 == surface_ref1, "Expected surface_ref2 == surface_ref1, got surface_ref1 = %u, surface_ref2 = %u.\n",
3726 surface_ref1, surface_ref2);
3727 /* In version 3, d3drm will destroy all references of the depth surface it created internally. */
3728 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3729 todo_wine ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x.\n", hr);
3730 if (SUCCEEDED(hr))
3731 IDirectDrawSurface_Release(ds);
3732 ref1 = IDirectDrawSurface_Release(surface);
3733 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3735 memset(&desc, 0, sizeof(desc));
3736 desc.dwSize = sizeof(desc);
3737 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3738 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3739 desc.dwWidth = rc.right;
3740 desc.dwHeight = rc.bottom;
3742 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3743 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3745 memset(&desc, 0, sizeof(desc));
3746 desc.dwSize = sizeof(desc);
3747 desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3748 desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | (use_sysmem_zbuffer ? DDSCAPS_SYSTEMMEMORY : 0);
3749 desc.dwZBufferBitDepth = 16;
3750 desc.dwWidth = rc.right;
3751 desc.dwHeight = rc.bottom;
3752 hr = IDirectDraw_CreateSurface(ddraw, &desc, &ds, NULL);
3753 ok(hr == DD_OK, "Cannot create depth surface (hr = %x).\n", hr);
3754 hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
3755 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3757 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
3758 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3760 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3761 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3763 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3764 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3765 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3767 /* Check if depth surface matches the one we created */
3768 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3769 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3770 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3772 IDirectDrawSurface_Release(d3drm_ds);
3773 IDirectDrawSurface_Release(d3drm_surface);
3774 IDirectDrawSurface_Release(ds);
3775 IDirect3DDevice2_Release(d3ddevice2);
3776 IDirect3DRMDevice3_Release(device3);
3777 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3778 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3779 /* The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3780 ref1 = IDirectDrawSurface_Release(ds);
3781 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3783 /* What happens if we pass no flags and still attach our own depth surface? */
3784 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, 0, &device3);
3785 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3787 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3788 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3790 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3791 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3792 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3794 /* Check if depth surface matches the one we created */
3795 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3796 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3797 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
3799 IDirectDrawSurface_Release(d3drm_ds);
3800 IDirectDrawSurface_Release(d3drm_surface);
3801 IDirect3DDevice2_Release(d3ddevice2);
3802 IDirect3DRMDevice3_Release(device3);
3803 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &ds);
3804 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
3805 /*The render target still holds a reference to ds as the depth surface remains attached to it, so refcount will be 1*/
3806 ref1 = IDirectDrawSurface_Release(ds);
3807 ok(ref1 == 1, "Expected ref1 == 1, got %u.\n", ref1);
3808 ref1 = IDirectDrawSurface_Release(surface);
3809 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3811 memset(&desc, 0, sizeof(desc));
3812 desc.dwSize = sizeof(desc);
3813 desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3814 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3815 desc.dwWidth = rc.right;
3816 desc.dwHeight = rc.bottom;
3818 hr = IDirectDraw_CreateSurface(ddraw, &desc, &surface, NULL);
3819 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3821 /* What happens if we don't pass D3DRMDEVICE_NOZBUFFER and still not attach our own depth surface? */
3822 hr = IDirect3DRM3_CreateDeviceFromSurface(d3drm3, &driver, ddraw, surface, D3DRMDEVICE_NOZBUFFER, &device3);
3823 ok(SUCCEEDED(hr), "Cannot create IDirect3DRMDevice3 interface (hr = %x).\n", hr);
3825 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3826 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
3828 hr = IDirect3DDevice2_GetRenderTarget(d3ddevice2, &d3drm_surface);
3829 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3830 ok(surface == d3drm_surface, "Expected surface returned == %p, got %p.\n", surface, d3drm_surface);
3832 /* Check if depth surface matches the one we created */
3833 hr = IDirectDrawSurface_GetAttachedSurface(d3drm_surface, &caps, &d3drm_ds);
3834 ok(hr == DDERR_NOTFOUND, "Expected hr == DDERR_NOTFOUND, got %x).\n", hr);
3835 IDirectDrawSurface_Release(d3drm_surface);
3837 IDirect3DDevice2_Release(d3ddevice2);
3838 IDirect3DRMDevice3_Release(device3);
3839 ref1 = IDirectDrawSurface_Release(surface);
3840 ok(ref1 == 0, "Expected Render target refcount == 0, got %u.\n", ref1);
3841 IDirect3DRM3_Release(d3drm3);
3842 IDirect3DRM_Release(d3drm1);
3843 IDirectDraw_Release(ddraw);
3844 DestroyWindow(window);
3847 static IDirect3DDevice *create_device1(IDirectDraw *ddraw, HWND window, IDirectDrawSurface **ds)
3849 static const DWORD z_depths[] = { 32, 24, 16 };
3850 IDirectDrawSurface *surface;
3851 IDirect3DDevice *device = NULL;
3852 DDSURFACEDESC surface_desc;
3853 unsigned int i;
3854 HRESULT hr;
3855 RECT rc;
3857 GetClientRect(window, &rc);
3858 hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
3859 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
3861 memset(&surface_desc, 0, sizeof(surface_desc));
3862 surface_desc.dwSize = sizeof(surface_desc);
3863 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
3864 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
3865 surface_desc.dwWidth = rc.right;
3866 surface_desc.dwHeight = rc.bottom;
3868 hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
3869 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
3871 /* We used to use EnumDevices() for this, but it seems
3872 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
3873 * relationship with reality. */
3874 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
3876 memset(&surface_desc, 0, sizeof(surface_desc));
3877 surface_desc.dwSize = sizeof(surface_desc);
3878 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
3879 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
3880 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
3881 surface_desc.dwWidth = rc.right;
3882 surface_desc.dwHeight = rc.bottom;
3883 if (FAILED(IDirectDraw_CreateSurface(ddraw, &surface_desc, ds, NULL)))
3884 continue;
3886 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
3887 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
3888 if (FAILED(hr))
3890 IDirectDrawSurface_Release(*ds);
3891 continue;
3894 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device)))
3895 break;
3897 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
3898 IDirectDrawSurface_Release(*ds);
3899 *ds = NULL;
3902 IDirectDrawSurface_Release(surface);
3903 return device;
3906 static void test_create_device_from_d3d1(void)
3908 IDirectDraw *ddraw1 = NULL;
3909 IDirect3D *d3d1 = NULL;
3910 IDirect3DRM *d3drm1 = NULL;
3911 IDirect3DRMDevice *device1 = (IDirect3DRMDevice *)0xdeadbeef;
3912 IDirect3DRMDevice2 *device2;
3913 IDirect3DRMDevice3 *device3;
3914 IDirect3DDevice *d3ddevice1 = NULL, *d3drm_d3ddevice1 = NULL;
3915 IDirect3DDevice2 *d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
3916 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
3917 DWORD expected_flags;
3918 DDSCAPS caps = { DDSCAPS_ZBUFFER };
3919 DDSURFACEDESC desc;
3920 RECT rc;
3921 HWND window;
3922 ULONG ref1, ref2, device_ref1, device_ref2;
3923 HRESULT hr;
3925 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
3926 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
3928 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
3929 GetClientRect(window, &rc);
3931 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D, (void **)&d3d1);
3932 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
3934 /* Create the immediate mode device */
3935 d3ddevice1 = create_device1(ddraw1, window, &ds);
3936 if (d3ddevice1 == NULL)
3938 win_skip("Cannot create IM device, skipping tests.\n");
3939 IDirect3D_Release(d3d1);
3940 IDirectDraw_Release(ddraw1);
3941 return;
3943 device_ref1 = get_refcount((IUnknown *)d3ddevice1);
3945 hr = Direct3DRMCreate(&d3drm1);
3946 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
3947 ref1 = get_refcount((IUnknown *)d3drm1);
3949 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, NULL, d3ddevice1, &device1);
3950 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3951 ok(device1 == NULL, "Expected device returned == NULL, got %p.\n", device1);
3952 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, NULL, &device1);
3953 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3954 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, NULL);
3955 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
3957 hr = IDirect3DRM_CreateDeviceFromD3D(d3drm1, d3d1, d3ddevice1, &device1);
3958 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice interface (hr = %x)\n", hr);
3959 ref2 = get_refcount((IUnknown *)d3drm1);
3960 ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
3961 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
3962 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
3964 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device2);
3965 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
3966 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3ddevice2);
3967 ok(SUCCEEDED(hr), "Expected hr == DD_OK, got %x).\n", hr);
3968 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
3969 IDirect3DRMDevice2_Release(device2);
3971 d3ddevice2 = (IDirect3DDevice2 *)0xdeadbeef;
3972 hr = IDirect3DRMDevice_QueryInterface(device1, &IID_IDirect3DRMDevice2, (void **)&device3);
3973 ok(hr == DD_OK, "Cannot get IDirect3DRMDevice2 Interface (hr = %x).\n", hr);
3974 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3ddevice2);
3975 ok(hr == DD_OK, "Expected hr == DD_OK, got %x).\n", hr);
3976 ok(d3ddevice2 == NULL, "Expected d3ddevice2 == NULL, got %p.\n", d3ddevice2);
3977 IDirect3DRMDevice3_Release(device3);
3979 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
3980 NULL, &surface, surface_callback);
3981 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
3982 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
3984 hr = IDirect3DRMDevice_GetDirect3DDevice(device1, &d3drm_d3ddevice1);
3985 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice interface (hr = %x).\n", hr);
3986 ok(d3ddevice1 == d3drm_d3ddevice1, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice1, d3drm_d3ddevice1);
3988 /* Check properties of render target and depth surfaces */
3989 hr = IDirect3DDevice_QueryInterface(d3drm_d3ddevice1, &IID_IDirectDrawSurface, (void **)&surface);
3990 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
3992 memset(&desc, 0, sizeof(desc));
3993 desc.dwSize = sizeof(desc);
3994 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
3995 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
3997 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
3998 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
3999 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4000 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4001 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4002 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4004 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4005 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4006 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4008 desc.dwSize = sizeof(desc);
4009 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4010 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4012 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4013 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4014 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4015 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4016 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4018 IDirectDrawSurface_Release(d3drm_ds);
4019 IDirectDrawSurface_Release(ds);
4020 IDirectDrawSurface_Release(surface);
4021 IDirect3DDevice_Release(d3drm_d3ddevice1);
4022 IDirect3DRMDevice_Release(device1);
4023 ref2 = get_refcount((IUnknown *)d3drm1);
4024 ok(ref1 == ref2, "expected ref1 == ref2, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
4025 device_ref2 = get_refcount((IUnknown *)d3ddevice1);
4026 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4028 IDirect3DRM_Release(d3drm1);
4029 IDirect3DDevice_Release(d3ddevice1);
4030 IDirect3D_Release(d3d1);
4031 IDirectDraw_Release(ddraw1);
4032 DestroyWindow(window);
4035 static IDirect3DDevice2 *create_device2(IDirectDraw2 *ddraw, HWND window, IDirectDrawSurface **ds)
4037 static const DWORD z_depths[] = { 32, 24, 16 };
4038 IDirectDrawSurface *surface;
4039 IDirect3DDevice2 *device = NULL;
4040 DDSURFACEDESC surface_desc;
4041 IDirect3D2 *d3d;
4042 unsigned int i;
4043 HRESULT hr;
4044 RECT rc;
4046 GetClientRect(window, &rc);
4047 hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL);
4048 ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
4050 memset(&surface_desc, 0, sizeof(surface_desc));
4051 surface_desc.dwSize = sizeof(surface_desc);
4052 surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
4053 surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
4054 surface_desc.dwWidth = rc.right;
4055 surface_desc.dwHeight = rc.bottom;
4057 hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
4058 ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
4060 hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
4061 if (FAILED(hr))
4063 IDirectDrawSurface_Release(surface);
4064 *ds = NULL;
4065 return NULL;
4068 /* We used to use EnumDevices() for this, but it seems
4069 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
4070 * relationship with reality. */
4071 for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i)
4073 memset(&surface_desc, 0, sizeof(surface_desc));
4074 surface_desc.dwSize = sizeof(surface_desc);
4075 surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
4076 surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
4077 U2(surface_desc).dwZBufferBitDepth = z_depths[i];
4078 surface_desc.dwWidth = rc.right;
4079 surface_desc.dwHeight = rc.bottom;
4080 if (FAILED(IDirectDraw2_CreateSurface(ddraw, &surface_desc, ds, NULL)))
4081 continue;
4083 hr = IDirectDrawSurface_AddAttachedSurface(surface, *ds);
4084 ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
4085 if (FAILED(hr))
4087 IDirectDrawSurface_Release(*ds);
4088 continue;
4091 if (SUCCEEDED(IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device)))
4092 break;
4094 IDirectDrawSurface_DeleteAttachedSurface(surface, 0, *ds);
4095 IDirectDrawSurface_Release(*ds);
4096 *ds = NULL;
4099 IDirect3D2_Release(d3d);
4100 IDirectDrawSurface_Release(surface);
4101 return device;
4104 static void test_create_device_from_d3d2(void)
4106 IDirectDraw *ddraw1 = NULL;
4107 IDirectDraw2 *ddraw2 = NULL;
4108 IDirect3D2 *d3d2 = NULL;
4109 IDirect3DRM *d3drm1 = NULL;
4110 IDirect3DRM2 *d3drm2 = NULL;
4111 IDirect3DRMDevice2 *device2 = (IDirect3DRMDevice2 *)0xdeadbeef;
4112 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL;
4113 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4114 DWORD expected_flags;
4115 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4116 DDSURFACEDESC desc;
4117 RECT rc;
4118 HWND window;
4119 ULONG ref1, ref2, ref3, device_ref1, device_ref2;
4120 HRESULT hr;
4122 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4123 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4125 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
4126 GetClientRect(window, &rc);
4128 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
4129 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4130 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
4131 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
4133 /* Create the immediate mode device */
4134 d3ddevice2 = create_device2(ddraw2, window, &ds);
4135 if (d3ddevice2 == NULL)
4137 win_skip("Cannot create IM device, skipping tests.\n");
4138 IDirect3D2_Release(d3d2);
4139 IDirectDraw2_Release(ddraw2);
4140 IDirectDraw_Release(ddraw1);
4141 return;
4143 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
4145 hr = Direct3DRMCreate(&d3drm1);
4146 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4147 ref1 = get_refcount((IUnknown *)d3drm1);
4149 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
4150 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM2 interface (hr = %x).\n", hr);
4151 ref2 = get_refcount((IUnknown *)d3drm2);
4153 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, NULL, d3ddevice2, &device2);
4154 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4155 ok(device2 == NULL, "Expected device returned == NULL, got %p.\n", device2);
4156 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, NULL, &device2);
4157 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4158 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, NULL);
4159 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4161 hr = IDirect3DRM2_CreateDeviceFromD3D(d3drm2, d3d2, d3ddevice2, &device2);
4162 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice2 interface (hr = %x)\n", hr);
4163 ref3 = get_refcount((IUnknown *)d3drm1);
4164 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4165 ref3 = get_refcount((IUnknown *)d3drm2);
4166 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4167 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4168 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4170 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4171 NULL, &surface, surface_callback);
4172 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4173 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4175 hr = IDirect3DRMDevice2_GetDirect3DDevice2(device2, &d3drm_d3ddevice2);
4176 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4177 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
4179 /* Check properties of render target and depth surfaces */
4180 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
4181 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4183 memset(&desc, 0, sizeof(desc));
4184 desc.dwSize = sizeof(desc);
4185 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4186 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4188 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4189 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4190 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4191 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4192 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4193 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4195 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4196 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4197 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4199 desc.dwSize = sizeof(desc);
4200 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4201 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4203 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4204 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4205 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4206 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4207 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4209 IDirectDrawSurface_Release(d3drm_ds);
4210 IDirectDrawSurface_Release(ds);
4211 IDirectDrawSurface_Release(surface);
4212 IDirect3DDevice2_Release(d3drm_d3ddevice2);
4213 IDirect3DRMDevice2_Release(device2);
4214 ref3 = get_refcount((IUnknown *)d3drm1);
4215 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4216 ref3 = get_refcount((IUnknown *)d3drm2);
4217 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4218 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4219 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4221 IDirect3DRM2_Release(d3drm2);
4222 IDirect3DRM_Release(d3drm1);
4223 IDirect3DDevice2_Release(d3ddevice2);
4224 IDirect3D2_Release(d3d2);
4225 IDirectDraw2_Release(ddraw2);
4226 IDirectDraw_Release(ddraw1);
4227 DestroyWindow(window);
4230 static void test_create_device_from_d3d3(void)
4232 IDirectDraw *ddraw1 = NULL;
4233 IDirectDraw2 *ddraw2 = NULL;
4234 IDirect3D2 *d3d2 = NULL;
4235 IDirect3DRM *d3drm1 = NULL;
4236 IDirect3DRM3 *d3drm3 = NULL;
4237 IDirect3DRMDevice3 *device3 = (IDirect3DRMDevice3 *)0xdeadbeef;
4238 IDirect3DDevice2 *d3ddevice2 = NULL, *d3drm_d3ddevice2 = NULL;
4239 IDirectDrawSurface *surface = NULL, *ds = NULL, *d3drm_ds = NULL;
4240 DWORD expected_flags;
4241 DDSCAPS caps = { DDSCAPS_ZBUFFER };
4242 DDSURFACEDESC desc;
4243 RECT rc;
4244 HWND window;
4245 ULONG ref1, ref2, ref3, device_ref1, device_ref2;
4246 HRESULT hr;
4248 hr = DirectDrawCreate(NULL, &ddraw1, NULL);
4249 ok(hr == DD_OK, "Cannot get IDirectDraw interface (hr = %x).\n", hr);
4251 window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
4252 GetClientRect(window, &rc);
4254 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirect3D2, (void **)&d3d2);
4255 ok(hr == DD_OK, "Cannot get IDirect3D2 interface (hr = %x).\n", hr);
4256 hr = IDirectDraw_QueryInterface(ddraw1, &IID_IDirectDraw2, (void **)&ddraw2);
4257 ok(hr == DD_OK, "Cannot get IDirectDraw2 interface (hr = %x).\n", hr);
4259 /* Create the immediate mode device */
4260 d3ddevice2 = create_device2(ddraw2, window, &ds);
4261 if (d3ddevice2 == NULL)
4263 win_skip("Cannot create IM device, skipping tests.\n");
4264 IDirect3D2_Release(d3d2);
4265 IDirectDraw2_Release(ddraw2);
4266 IDirectDraw_Release(ddraw1);
4267 return;
4269 device_ref1 = get_refcount((IUnknown *)d3ddevice2);
4271 hr = Direct3DRMCreate(&d3drm1);
4272 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x).\n", hr);
4273 ref1 = get_refcount((IUnknown *)d3drm1);
4275 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
4276 ok(hr == D3DRM_OK, "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
4277 ref2 = get_refcount((IUnknown *)d3drm3);
4279 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, NULL, d3ddevice2, &device3);
4280 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4281 ok(device3 == NULL, "Expected device returned == NULL, got %p.\n", device3);
4282 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, NULL, &device3);
4283 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4284 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, NULL);
4285 ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
4287 hr = IDirect3DRM3_CreateDeviceFromD3D(d3drm3, d3d2, d3ddevice2, &device3);
4288 ok(hr == DD_OK, "Failed to create IDirect3DRMDevice3 interface (hr = %x)\n", hr);
4289 ref3 = get_refcount((IUnknown *)d3drm1);
4290 ok(ref3 > ref1, "expected ref3 > ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
4291 ref3 = get_refcount((IUnknown *)d3drm3);
4292 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4293 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4294 ok(device_ref2 > device_ref1, "Expected device_ref2 > device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4296 hr = IDirectDraw_EnumSurfaces(ddraw1, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
4297 NULL, &surface, surface_callback);
4298 ok(hr == DD_OK, "Failed to enumerate surfaces (hr = %x).\n", hr);
4299 ok(surface == NULL, "No primary surface should have enumerated (%p).\n", surface);
4301 hr = IDirect3DRMDevice3_GetDirect3DDevice2(device3, &d3drm_d3ddevice2);
4302 ok(hr == D3DRM_OK, "Cannot get IDirect3DDevice2 interface (hr = %x).\n", hr);
4303 ok(d3ddevice2 == d3drm_d3ddevice2, "Expected Immediate Mode device created == %p, got %p.\n", d3ddevice2, d3drm_d3ddevice2);
4305 /* Check properties of render target and depth surfaces */
4306 hr = IDirect3DDevice2_GetRenderTarget(d3drm_d3ddevice2, &surface);
4307 ok(hr == DD_OK, "Cannot get surface to the render target (hr = %x).\n", hr);
4309 memset(&desc, 0, sizeof(desc));
4310 desc.dwSize = sizeof(desc);
4311 hr = IDirectDrawSurface_GetSurfaceDesc(surface, &desc);
4312 ok(hr == DD_OK, "Cannot get surface desc structure (hr = %x).\n", hr);
4314 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4315 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4316 ok((desc.ddsCaps.dwCaps & (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE)) == (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE),
4317 "Expected caps containing %x, got %x.\n", DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE, desc.ddsCaps.dwCaps);
4318 expected_flags = DDSD_PIXELFORMAT | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4319 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4321 hr = IDirectDrawSurface_GetAttachedSurface(surface, &caps, &d3drm_ds);
4322 ok(hr == DD_OK, "Cannot get attached depth surface (hr = %x).\n", hr);
4323 ok(ds == d3drm_ds, "Expected depth surface (%p) == surface created internally (%p).\n", ds, d3drm_ds);
4325 desc.dwSize = sizeof(desc);
4326 hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc);
4327 ok(hr == DD_OK, "Cannot get z surface desc structure (hr = %x).\n", hr);
4329 ok((desc.dwWidth == rc.right) && (desc.dwHeight == rc.bottom), "Expected surface dimensions = %u, %u, got %u, %u.\n",
4330 rc.right, rc.bottom, desc.dwWidth, desc.dwHeight);
4331 ok((desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER) == DDSCAPS_ZBUFFER, "Expected caps containing %x, got %x.\n", DDSCAPS_ZBUFFER, desc.ddsCaps.dwCaps);
4332 expected_flags = DDSD_ZBUFFERBITDEPTH | DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PITCH;
4333 ok(desc.dwFlags == expected_flags, "Expected %x for flags, got %x.\n", expected_flags, desc.dwFlags);
4335 IDirectDrawSurface_Release(d3drm_ds);
4336 IDirectDrawSurface_Release(ds);
4337 IDirectDrawSurface_Release(surface);
4338 IDirect3DDevice2_Release(d3drm_d3ddevice2);
4339 IDirect3DRMDevice3_Release(device3);
4340 ref3 = get_refcount((IUnknown *)d3drm1);
4341 ok(ref1 == ref3, "expected ref1 == ref3, got ref1 = %u, ref3 = %u.\n", ref1, ref3);
4342 ref3 = get_refcount((IUnknown *)d3drm3);
4343 ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
4344 device_ref2 = get_refcount((IUnknown *)d3ddevice2);
4345 ok(device_ref2 == device_ref1, "Expected device_ref2 == device_ref1, got device_ref1 = %u, device_ref2 = %u.\n", device_ref1, device_ref2);
4347 IDirect3DRM3_Release(d3drm3);
4348 IDirect3DRM_Release(d3drm1);
4349 IDirect3DDevice2_Release(d3ddevice2);
4350 IDirect3D2_Release(d3d2);
4351 IDirectDraw2_Release(ddraw2);
4352 IDirectDraw_Release(ddraw1);
4353 DestroyWindow(window);
4356 static char *create_bitmap(unsigned int w, unsigned int h, BOOL palettized)
4358 unsigned int bpp = palettized ? 8 : 24;
4359 BITMAPFILEHEADER file_header;
4360 DWORD written, size, ret;
4361 unsigned char *buffer;
4362 char path[MAX_PATH];
4363 unsigned int i, j;
4364 BITMAPINFO *info;
4365 char *filename;
4366 HANDLE file;
4368 ret = GetTempPathA(MAX_PATH, path);
4369 ok(ret, "Failed to get temporary file path.\n");
4370 filename = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
4371 ret = GetTempFileNameA(path, "d3d", 0, filename);
4372 ok(ret, "Failed to get filename.\n");
4373 file = CreateFileA(filename, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
4374 ok(file != INVALID_HANDLE_VALUE, "Failed to open temporary file \"%s\".\n", filename);
4376 size = FIELD_OFFSET(BITMAPINFO, bmiColors[palettized ? 256 : 0]);
4378 memset(&file_header, 0, sizeof(file_header));
4379 file_header.bfType = 0x4d42; /* BM */
4380 file_header.bfOffBits = sizeof(file_header) + size;
4381 file_header.bfSize = file_header.bfOffBits + w * h * (bpp / 8);
4382 ret = WriteFile(file, &file_header, sizeof(file_header), &written, NULL);
4383 ok(ret && written == sizeof(file_header), "Failed to write file header.\n");
4385 info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4386 info->bmiHeader.biSize = sizeof(info->bmiHeader);
4387 info->bmiHeader.biBitCount = bpp;
4388 info->bmiHeader.biPlanes = 1;
4389 info->bmiHeader.biWidth = w;
4390 info->bmiHeader.biHeight = h;
4391 info->bmiHeader.biCompression = BI_RGB;
4392 if (palettized)
4394 for (i = 0; i < 256; ++i)
4396 info->bmiColors[i].rgbBlue = i;
4397 info->bmiColors[i].rgbGreen = i;
4398 info->bmiColors[i].rgbRed = i;
4401 ret = WriteFile(file, info, size, &written, NULL);
4402 ok(ret && written == size, "Failed to write bitmap info.\n");
4403 HeapFree(GetProcessHeap(), 0, info);
4405 size = w * h * (bpp / 8);
4406 buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
4407 for (i = 0, j = 0; i < size;)
4409 if (palettized)
4411 buffer[i++] = j++;
4412 j %= 256;
4414 else
4416 buffer[i++] = j % 251;
4417 buffer[i++] = j % 239;
4418 buffer[i++] = j++ % 247;
4421 ret = WriteFile(file, buffer, size, &written, NULL);
4422 ok(ret && written == size, "Failed to write bitmap data.\n");
4423 HeapFree(GetProcessHeap(), 0, buffer);
4425 CloseHandle(file);
4427 return filename;
4430 static void test_bitmap_data(unsigned int test_idx, const D3DRMIMAGE *img,
4431 BOOL upside_down, unsigned int w, unsigned int h, BOOL palettized)
4433 const unsigned char *data = img->buffer1;
4434 unsigned int i, j;
4436 ok(img->width == w, "Test %u: Got unexpected image width %u, expected %u.\n", test_idx, img->width, w);
4437 ok(img->height == h, "Test %u: Got unexpected image height %u, expected %u.\n", test_idx, img->height, h);
4438 ok(img->aspectx == 1, "Test %u: Got unexpected image aspectx %u.\n", test_idx, img->aspectx);
4439 ok(img->aspecty == 1, "Test %u: Got unexpected image aspecty %u.\n", test_idx, img->aspecty);
4440 ok(!img->buffer2, "Test %u: Got unexpected image buffer2 %p.\n", test_idx, img->buffer2);
4442 /* The image is palettized if the total number of colors used is <= 256. */
4443 if (w * h > 256 && !palettized)
4445 /* D3drm aligns the 24bpp texture to 4 bytes in the buffer, with one
4446 * byte padding from 24bpp texture. */
4447 ok(img->depth == 32, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
4448 ok(img->rgb == TRUE, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
4449 ok(img->bytes_per_line == w * 4, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
4450 test_idx, img->bytes_per_line, w * 4);
4451 ok(img->red_mask == 0xff0000, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
4452 ok(img->green_mask == 0x00ff00, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
4453 ok(img->blue_mask == 0x0000ff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
4454 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
4455 ok(!img->palette_size, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
4456 ok(!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
4457 for (i = 0; i < h; ++i)
4459 for (j = 0; j < w; ++j)
4461 const unsigned char *ptr = &data[i * img->bytes_per_line + j * 4];
4462 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
4464 if (ptr[0] != idx % 251 || ptr[1] != idx % 239 || ptr[2] != idx % 247 || ptr[3] != 0xff)
4466 ok(0, "Test %u: Got unexpected color 0x%02x%02x%02x%02x at position %u, %u, "
4467 "expected 0x%02x%02x%02x%02x.\n", test_idx, ptr[0], ptr[1], ptr[2], ptr[3],
4468 j, i, idx % 251, idx % 239, idx % 247, 0xff);
4469 return;
4473 return;
4476 ok(img->depth == 8, "Test %u: Got unexpected image depth %u.\n", test_idx, img->depth);
4477 ok(!img->rgb, "Test %u: Got unexpected image rgb %#x.\n", test_idx, img->rgb);
4478 ok(img->red_mask == 0xff, "Test %u: Got unexpected image red mask %#x.\n", test_idx, img->red_mask);
4479 ok(img->green_mask == 0xff, "Test %u: Got unexpected image green mask %#x.\n", test_idx, img->green_mask);
4480 ok(img->blue_mask == 0xff, "Test %u: Got unexpected image blue mask %#x.\n", test_idx, img->blue_mask);
4481 ok(!img->alpha_mask, "Test %u: Got unexpected image alpha mask %#x.\n", test_idx, img->alpha_mask);
4482 ok(!!img->palette, "Test %u: Got unexpected image palette %p.\n", test_idx, img->palette);
4483 if (!palettized)
4485 /* In this case, bytes_per_line is aligned to the next multiple of
4486 * 4 from width. */
4487 ok(img->bytes_per_line == ((w + 3) & ~3), "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
4488 test_idx, img->bytes_per_line, (w + 3) & ~3);
4489 ok(img->palette_size == w * h, "Test %u: Got unexpected palette size %u, expected %u.\n",
4490 test_idx, img->palette_size, w * h);
4491 for (i = 0; i < img->palette_size; ++i)
4493 unsigned int idx = upside_down ? (h - 1) * w - i + (i % w) * 2 : i;
4494 ok(img->palette[i].red == idx % 251
4495 && img->palette[i].green == idx % 239 && img->palette[i].blue == idx % 247,
4496 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
4497 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
4498 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
4499 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
4500 test_idx, i, img->palette[i].flags);
4502 for (i = 0; i < h; ++i)
4504 for (j = 0; j < w; ++j)
4506 if (data[i * img->bytes_per_line + j] != i * w + j)
4508 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
4509 test_idx, data[i * img->bytes_per_line + j], j, i, i * w + j);
4510 return;
4514 return;
4517 /* bytes_per_line is not always aligned by d3drm depending on the
4518 * format. */
4519 ok(img->bytes_per_line == w, "Test %u: Got unexpected image bytes per line %u, expected %u.\n",
4520 test_idx, img->bytes_per_line, w);
4521 ok(img->palette_size == 256, "Test %u: Got unexpected palette size %u.\n", test_idx, img->palette_size);
4522 for (i = 0; i < 256; ++i)
4524 ok(img->palette[i].red == i && img->palette[i].green == i && img->palette[i].blue == i,
4525 "Test %u: Got unexpected palette entry (%u) color 0x%02x%02x%02x.\n",
4526 test_idx, i, img->palette[i].red, img->palette[i].green, img->palette[i].blue);
4527 ok(img->palette[i].flags == D3DRMPALETTE_READONLY,
4528 "Test %u: Got unexpected palette entry (%u) flags %#x.\n",
4529 test_idx, i, img->palette[i].flags);
4531 for (i = 0; i < h; ++i)
4533 for (j = 0; j < w; ++j)
4535 unsigned int idx = upside_down ? (h - 1 - i) * w + j : i * w + j;
4536 if (data[i * img->bytes_per_line + j] != idx % 256)
4538 ok(0, "Test %u: Got unexpected color 0x%02x at position %u, %u, expected 0x%02x.\n",
4539 test_idx, data[i * img->bytes_per_line + j], j, i, idx % 256);
4540 return;
4546 static void test_load_texture(void)
4548 IDirect3DRMTexture3 *texture3;
4549 IDirect3DRMTexture2 *texture2;
4550 IDirect3DRMTexture *texture1;
4551 D3DRMIMAGE *d3drm_img;
4552 IDirect3DRM3 *d3drm3;
4553 IDirect3DRM2 *d3drm2;
4554 IDirect3DRM *d3drm1;
4555 char *filename;
4556 HRESULT hr;
4557 BOOL ret;
4558 int i;
4560 static const struct
4562 unsigned int w;
4563 unsigned int h;
4564 BOOL palettized;
4566 tests[] =
4568 {100, 100, TRUE },
4569 {99, 100, TRUE },
4570 {100, 100, FALSE},
4571 {99, 100, FALSE},
4572 {3, 39, FALSE},
4575 hr = Direct3DRMCreate(&d3drm1);
4576 ok(hr == D3DRM_OK, "Failed to create IDirect3DRM object, hr %#x.\n", hr);
4577 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
4578 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM2 interface, hr %#x.\n", hr);
4579 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
4580 ok(SUCCEEDED(hr), "Failed to get IDirect3DRM3 interface, hr %#x.\n", hr);
4582 for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
4584 filename = create_bitmap(tests[i].w, tests[i].h, tests[i].palettized);
4586 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
4587 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
4588 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
4589 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
4590 if (d3drm_img)
4591 test_bitmap_data(i * 4, d3drm_img, FALSE, tests[i].w, tests[i].h, tests[i].palettized);
4592 IDirect3DRMTexture_Release(texture1);
4594 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
4595 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
4596 d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
4597 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
4598 if (d3drm_img)
4599 test_bitmap_data(i * 4 + 1, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
4600 IDirect3DRMTexture2_Release(texture2);
4602 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
4603 ok(SUCCEEDED(hr), "Test %u: Failed to load texture, hr %#x.\n", i, hr);
4604 d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
4605 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
4606 if (d3drm_img)
4607 test_bitmap_data(i * 4 + 2, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
4608 /* Test whether querying a version 1 texture from version 3 causes a
4609 * change in the loading behavior. */
4610 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IDirect3DRMTexture, (void **)&texture1);
4611 ok(SUCCEEDED(hr), "Failed to get IDirect3DRMTexture interface, hr %#x.\n", hr);
4612 d3drm_img = IDirect3DRMTexture_GetImage(texture1);
4613 todo_wine ok(!!d3drm_img, "Test %u: Failed to get image.\n", i);
4614 if (d3drm_img)
4615 test_bitmap_data(i * 4 + 3, d3drm_img, TRUE, tests[i].w, tests[i].h, tests[i].palettized);
4616 IDirect3DRMTexture_Release(texture1);
4617 IDirect3DRMTexture3_Release(texture3);
4619 ret = DeleteFileA(filename);
4620 ok(ret, "Test %u: Failed to delete bitmap \"%s\".\n", i, filename);
4621 HeapFree(GetProcessHeap(), 0, filename);
4624 IDirect3DRM3_Release(d3drm3);
4625 IDirect3DRM2_Release(d3drm2);
4626 IDirect3DRM_Release(d3drm1);
4629 static void test_texture_qi(void)
4631 static const struct qi_test tests[] =
4633 { &IID_IDirect3DRM3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4634 { &IID_IDirect3DRM2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4635 { &IID_IDirect3DRM, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4636 { &IID_IDirect3DRMDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4637 { &IID_IDirect3DRMDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4638 { &IID_IDirect3DRMDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4639 { &IID_IDirect3DRMWinDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4640 { &IID_IDirect3DRMObject, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
4641 { &IID_IDirect3DRMViewport, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4642 { &IID_IDirect3DRMViewport2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4643 { &IID_IDirect3DRMFrame, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4644 { &IID_IDirect3DRMFrame2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4645 { &IID_IDirect3DRMFrame3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4646 { &IID_IDirect3DRMVisual, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
4647 { &IID_IDirect3DRMMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4648 { &IID_IDirect3DRMMeshBuilder, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4649 { &IID_IDirect3DRMMeshBuilder2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4650 { &IID_IDirect3DRMMeshBuilder3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4651 { &IID_IDirect3DRMFace, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4652 { &IID_IDirect3DRMFace2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4653 { &IID_IDirect3DRMLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4654 { &IID_IDirect3DRMTexture, &IID_IUnknown, &IID_IDirect3DRMTexture, S_OK },
4655 { &IID_IDirect3DRMTexture2, &IID_IUnknown, &IID_IDirect3DRMTexture2, S_OK },
4656 { &IID_IDirect3DRMTexture3, &IID_IUnknown, &IID_IDirect3DRMTexture3, S_OK },
4657 { &IID_IDirect3DRMWrap, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4658 { &IID_IDirect3DRMMaterial, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4659 { &IID_IDirect3DRMMaterial2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4660 { &IID_IDirect3DRMAnimation, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4661 { &IID_IDirect3DRMAnimation2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4662 { &IID_IDirect3DRMAnimationSet, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4663 { &IID_IDirect3DRMAnimationSet2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4664 { &IID_IDirect3DRMObjectArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4665 { &IID_IDirect3DRMDeviceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4666 { &IID_IDirect3DRMViewportArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4667 { &IID_IDirect3DRMFrameArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4668 { &IID_IDirect3DRMVisualArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4669 { &IID_IDirect3DRMLightArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4670 { &IID_IDirect3DRMPickedArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4671 { &IID_IDirect3DRMFaceArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4672 { &IID_IDirect3DRMAnimationArray, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4673 { &IID_IDirect3DRMUserVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4674 { &IID_IDirect3DRMShadow, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4675 { &IID_IDirect3DRMShadow2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4676 { &IID_IDirect3DRMInterpolator, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4677 { &IID_IDirect3DRMProgressiveMesh, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4678 { &IID_IDirect3DRMPicked2Array, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4679 { &IID_IDirect3DRMClippedVisual, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4680 { &IID_IDirectDrawClipper, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4681 { &IID_IDirectDrawSurface7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4682 { &IID_IDirectDrawSurface4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4683 { &IID_IDirectDrawSurface3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4684 { &IID_IDirectDrawSurface2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4685 { &IID_IDirectDrawSurface, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4686 { &IID_IDirect3DDevice7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4687 { &IID_IDirect3DDevice3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4688 { &IID_IDirect3DDevice2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4689 { &IID_IDirect3DDevice, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4690 { &IID_IDirect3D7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4691 { &IID_IDirect3D3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4692 { &IID_IDirect3D2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4693 { &IID_IDirect3D, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4694 { &IID_IDirectDraw7, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4695 { &IID_IDirectDraw4, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4696 { &IID_IDirectDraw3, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4697 { &IID_IDirectDraw2, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4698 { &IID_IDirectDraw, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4699 { &IID_IDirect3DLight, NULL, NULL, CLASS_E_CLASSNOTAVAILABLE },
4700 { &IID_IUnknown, &IID_IUnknown, NULL, S_OK, },
4702 HRESULT hr;
4703 IDirect3DRM *d3drm1;
4704 IDirect3DRM2 *d3drm2;
4705 IDirect3DRM3 *d3drm3;
4706 IDirect3DRMTexture *texture1;
4707 IDirect3DRMTexture2 *texture2;
4708 IDirect3DRMTexture3 *texture3;
4709 IUnknown *unknown;
4710 char *filename;
4711 BOOL check;
4713 hr = Direct3DRMCreate(&d3drm1);
4714 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM interface (hr = %#x)\n", hr);
4715 filename = create_bitmap(1, 1, TRUE);
4716 hr = IDirect3DRM_LoadTexture(d3drm1, filename, &texture1);
4717 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
4718 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %#x)\n", hr);
4719 hr = IDirect3DRMTexture_QueryInterface(texture1, &IID_IUnknown, (void **)&unknown);
4720 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture (hr = %#x)\n", hr);
4721 IDirect3DRMTexture_Release(texture1);
4722 test_qi("texture1_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
4723 IUnknown_Release(unknown);
4725 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
4726 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %#x).\n", hr);
4727 hr = IDirect3DRM2_LoadTexture(d3drm2, filename, &texture2);
4728 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
4729 hr = IDirect3DRMTexture2_QueryInterface(texture2, &IID_IUnknown, (void **)&unknown);
4730 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture2 (hr = %#x)\n", hr);
4731 IDirect3DRMTexture2_Release(texture2);
4732 test_qi("texture2_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
4733 IUnknown_Release(unknown);
4735 hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
4736 ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr);
4737 hr = IDirect3DRM3_LoadTexture(d3drm3, filename, &texture3);
4738 ok(SUCCEEDED(hr), "Failed to load texture (hr = %#x).\n", hr);
4739 ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %#x)\n", hr);
4740 hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IUnknown, (void **)&unknown);
4741 ok(SUCCEEDED(hr), "Cannot get IUnknown interface from IDirect3DRMTexture3 (hr = %#x)\n", hr);
4742 IDirect3DRMTexture3_Release(texture3);
4743 test_qi("texture3_qi", unknown, &IID_IUnknown, tests, sizeof(tests) / sizeof(*tests));
4744 IUnknown_Release(unknown);
4746 IDirect3DRM3_Release(d3drm3);
4747 IDirect3DRM2_Release(d3drm2);
4748 IDirect3DRM_Release(d3drm1);
4749 check = DeleteFileA(filename);
4750 ok(check, "Cannot delete image stored in %s (error = %d).\n", filename, GetLastError());
4751 HeapFree(GetProcessHeap(), 0, filename);
4754 START_TEST(d3drm)
4756 test_MeshBuilder();
4757 test_MeshBuilder3();
4758 test_Mesh();
4759 test_Face();
4760 test_Frame();
4761 test_Device();
4762 test_object();
4763 test_Viewport();
4764 test_Light();
4765 test_Material2();
4766 test_Texture();
4767 test_frame_transform();
4768 test_d3drm_load();
4769 test_frame_mesh_materials();
4770 test_d3drm_qi();
4771 test_frame_qi();
4772 test_device_qi();
4773 test_create_device_from_clipper1();
4774 test_create_device_from_clipper2();
4775 test_create_device_from_clipper3();
4776 test_create_device_from_surface1();
4777 test_create_device_from_surface2();
4778 test_create_device_from_surface3();
4779 test_create_device_from_d3d1();
4780 test_create_device_from_d3d2();
4781 test_create_device_from_d3d3();
4782 test_load_texture();
4783 test_texture_qi();