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