From 9ee120f108333ff53bb96ac36131d2d776a02fb8 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Wed, 5 Mar 2014 10:46:38 +0100 Subject: [PATCH] ddraw/tests: Avoid using EnumDevices() to get a supported Z buffer format. --- dlls/ddraw/tests/ddraw1.c | 112 ++++++++++++++++---------------------- dlls/ddraw/tests/ddraw2.c | 97 +++++++++++++++++---------------- 2 files changed, 96 insertions(+), 113 deletions(-) diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index c0ad9619768..edf750e80a2 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -208,22 +208,28 @@ static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr); } -static HRESULT CALLBACK enum_z_fmt(GUID *guid, char *description, char *name, - D3DDEVICEDESC *hal_desc, D3DDEVICEDESC *hel_desc, void *ctx) +static DWORD get_device_z_depth(IDirect3DDevice *device) { - DWORD *z_depth = ctx; + DDSCAPS caps = {DDSCAPS_ZBUFFER}; + IDirectDrawSurface *ds, *rt; + DDSURFACEDESC desc; + HRESULT hr; - if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid)) - return D3DENUMRET_OK; + if (FAILED(IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt))) + return 0; - if (hal_desc->dwDeviceZBufferBitDepth & DDBD_32) - *z_depth = 32; - else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24) - *z_depth = 24; - else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16) - *z_depth = 16; + hr = IDirectDrawSurface_GetAttachedSurface(rt, &caps, &ds); + IDirectDrawSurface_Release(rt); + if (FAILED(hr)) + return 0; - return DDENUMRET_OK; + desc.dwSize = sizeof(desc); + hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc); + IDirectDrawSurface_Release(ds); + if (FAILED(hr)) + return 0; + + return U2(desc).dwZBufferBitDepth; } static IDirectDraw *create_ddraw(void) @@ -794,7 +800,6 @@ static void test_coop_level_d3d_state(void) static void test_surface_interface_mismatch(void) { IDirectDraw *ddraw = NULL; - IDirect3D *d3d = NULL; IDirectDrawSurface *surface = NULL, *ds; IDirectDrawSurface3 *surface3 = NULL; IDirect3DDevice *device = NULL; @@ -817,8 +822,17 @@ static void test_surface_interface_mismatch(void) goto cleanup; } - hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + if (!(device = create_device(ddraw, window, DDSCL_NORMAL))) + { + skip("Failed to create a 3D device, skipping test.\n"); + IDirectDraw_Release(ddraw); + DestroyWindow(window); + return; + } + z_depth = get_device_z_depth(device); + ok(!!z_depth, "Failed to get device z depth.\n"); + IDirect3DDevice_Release(device); + device = NULL; memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); @@ -837,19 +851,6 @@ static void test_surface_interface_mismatch(void) goto cleanup; } - if (FAILED(hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d))) - { - skip("D3D interface is not available, skipping test.\n"); - goto cleanup; - } - - hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth); - if (FAILED(hr) || !z_depth) - { - skip("No depth buffer formats available, skipping test.\n"); - goto cleanup; - } - memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; @@ -893,7 +894,6 @@ cleanup: if (surface3) IDirectDrawSurface3_Release(surface3); if (surface) IDirectDrawSurface_Release(surface); if (device) IDirect3DDevice_Release(device); - if (d3d) IDirect3D_Release(d3d); if (ddraw) IDirectDraw_Release(ddraw); DestroyWindow(window); } @@ -3186,9 +3186,9 @@ static void test_rt_caps(void) { PALETTEENTRY palette_entries[256]; IDirectDrawPalette *palette; + IDirect3DDevice *device; IDirectDraw *ddraw; DWORD z_depth = 0; - IDirect3D *d3d; unsigned int i; ULONG refcount; HWND window; @@ -3360,22 +3360,16 @@ static void test_rt_caps(void) window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0); - hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); - - if (FAILED(hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d))) + if (!(device = create_device(ddraw, window, DDSCL_NORMAL))) { - skip("D3D interface is not available, skipping test.\n"); - goto done; - } - - hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth); - if (FAILED(hr) || !z_depth) - { - skip("No depth buffer formats available, skipping test.\n"); - IDirect3D_Release(d3d); - goto done; + skip("Failed to create a 3D device, skipping test.\n"); + IDirectDraw_Release(ddraw); + DestroyWindow(window); + return; } + z_depth = get_device_z_depth(device); + ok(!!z_depth, "Failed to get device z depth.\n"); + IDirect3DDevice_Release(device); memset(palette_entries, 0, sizeof(palette_entries)); hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL); @@ -3442,9 +3436,6 @@ static void test_rt_caps(void) } IDirectDrawPalette_Release(palette); - IDirect3D_Release(d3d); - -done: refcount = IDirectDraw_Release(ddraw); ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount); DestroyWindow(window); @@ -3609,8 +3600,8 @@ static void test_primary_caps(void) static void test_surface_lock(void) { IDirectDraw *ddraw; - IDirect3D *d3d = NULL; IDirectDrawSurface *surface; + IDirect3DDevice *device; HRESULT hr; HWND window; unsigned int i; @@ -3662,21 +3653,16 @@ static void test_surface_lock(void) window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0); - hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); - - if (FAILED(hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d))) + if (!(device = create_device(ddraw, window, DDSCL_NORMAL))) { - skip("D3D interface is not available, skipping test.\n"); - goto done; - } - - hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth); - if (FAILED(hr) || !z_depth) - { - skip("No depth buffer formats available, skipping test.\n"); - goto done; + skip("Failed to create a 3D device, skipping test.\n"); + IDirectDraw_Release(ddraw); + DestroyWindow(window); + return; } + z_depth = get_device_z_depth(device); + ok(!!z_depth, "Failed to get device z depth.\n"); + IDirect3DDevice_Release(device); for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { @@ -3712,10 +3698,6 @@ static void test_surface_lock(void) IDirectDrawSurface_Release(surface); } - -done: - if (d3d) - IDirect3D_Release(d3d); refcount = IDirectDraw_Release(ddraw); ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount); DestroyWindow(window); diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index fef2d304fd5..26262117376 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -140,22 +140,28 @@ static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y) return color; } -static HRESULT CALLBACK enum_z_fmt(GUID *guid, char *description, char *name, - D3DDEVICEDESC *hal_desc, D3DDEVICEDESC *hel_desc, void *ctx) +static DWORD get_device_z_depth(IDirect3DDevice2 *device) { - DWORD *z_depth = ctx; + DDSCAPS caps = {DDSCAPS_ZBUFFER}; + IDirectDrawSurface *ds, *rt; + DDSURFACEDESC desc; + HRESULT hr; - if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid)) - return D3DENUMRET_OK; + if (FAILED(IDirect3DDevice2_GetRenderTarget(device, &rt))) + return 0; - if (hal_desc->dwDeviceZBufferBitDepth & DDBD_32) - *z_depth = 32; - else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24) - *z_depth = 24; - else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16) - *z_depth = 16; + hr = IDirectDrawSurface_GetAttachedSurface(rt, &caps, &ds); + IDirectDrawSurface_Release(rt); + if (FAILED(hr)) + return 0; - return DDENUMRET_OK; + desc.dwSize = sizeof(desc); + hr = IDirectDrawSurface_GetSurfaceDesc(ds, &desc); + IDirectDrawSurface_Release(ds); + if (FAILED(hr)) + return 0; + + return U2(desc).dwZBufferBitDepth; } static IDirectDraw2 *create_ddraw(void) @@ -780,8 +786,17 @@ static void test_surface_interface_mismatch(void) goto cleanup; } - hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + if (!(device = create_device(ddraw, window, DDSCL_NORMAL))) + { + skip("Failed to create a 3D device, skipping test.\n"); + IDirectDraw2_Release(ddraw); + DestroyWindow(window); + return; + } + z_depth = get_device_z_depth(device); + ok(!!z_depth, "Failed to get device z depth.\n"); + IDirect3DDevice2_Release(device); + device = NULL; memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); @@ -806,13 +821,6 @@ static void test_surface_interface_mismatch(void) goto cleanup; } - hr = IDirect3D2_EnumDevices(d3d, enum_z_fmt, &z_depth); - if (FAILED(hr) || !z_depth) - { - skip("No depth buffer formats available, skipping test.\n"); - goto cleanup; - } - memset(&surface_desc, 0, sizeof(surface_desc)); surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; @@ -3776,6 +3784,7 @@ static void test_rt_caps(void) { PALETTEENTRY palette_entries[256]; IDirectDrawPalette *palette; + IDirect3DDevice2 *device; IDirectDraw2 *ddraw; DWORD z_depth = 0; IDirect3D2 *d3d; @@ -3992,8 +4001,16 @@ static void test_rt_caps(void) window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0); - hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); + if (!(device = create_device(ddraw, window, DDSCL_NORMAL))) + { + skip("Failed to create a 3D device, skipping test.\n"); + IDirectDraw2_Release(ddraw); + DestroyWindow(window); + return; + } + z_depth = get_device_z_depth(device); + ok(!!z_depth, "Failed to get device z depth.\n"); + IDirect3DDevice2_Release(device); if (FAILED(hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d))) { @@ -4001,14 +4018,6 @@ static void test_rt_caps(void) goto done; } - hr = IDirect3D2_EnumDevices(d3d, enum_z_fmt, &z_depth); - if (FAILED(hr) || !z_depth) - { - skip("No depth buffer formats available, skipping test.\n"); - IDirect3D2_Release(d3d); - goto done; - } - memset(palette_entries, 0, sizeof(palette_entries)); hr = IDirectDraw2_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL); ok(SUCCEEDED(hr), "Failed to create palette, hr %#x.\n", hr); @@ -4297,8 +4306,8 @@ static void test_primary_caps(void) static void test_surface_lock(void) { IDirectDraw2 *ddraw; - IDirect3D2 *d3d = NULL; IDirectDrawSurface *surface; + IDirect3DDevice2 *device; HRESULT hr; HWND window; unsigned int i; @@ -4350,21 +4359,16 @@ static void test_surface_lock(void) window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0); - hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); - ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); - - if (FAILED(hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d))) + if (!(device = create_device(ddraw, window, DDSCL_NORMAL))) { - skip("D3D interface is not available, skipping test.\n"); - goto done; - } - - hr = IDirect3D2_EnumDevices(d3d, enum_z_fmt, &z_depth); - if (FAILED(hr) || !z_depth) - { - skip("No depth buffer formats available, skipping test.\n"); - goto done; + skip("Failed to create a 3D device, skipping test.\n"); + IDirectDraw2_Release(ddraw); + DestroyWindow(window); + return; } + z_depth = get_device_z_depth(device); + ok(!!z_depth, "Failed to get device z depth.\n"); + IDirect3DDevice2_Release(device); for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) { @@ -4400,9 +4404,6 @@ static void test_surface_lock(void) IDirectDrawSurface_Release(surface); } -done: - if (d3d) - IDirect3D2_Release(d3d); refcount = IDirectDraw2_Release(ddraw); ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount); DestroyWindow(window);