Commit 9ee120f1 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

ddraw/tests: Avoid using EnumDevices() to get a supported Z buffer format.

parent 75935f94
...@@ -208,22 +208,28 @@ static void set_execute_data(IDirect3DExecuteBuffer *execute_buffer, UINT vertex ...@@ -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); ok(SUCCEEDED(hr), "Failed to set execute data, hr %#x.\n", hr);
} }
static HRESULT CALLBACK enum_z_fmt(GUID *guid, char *description, char *name, static DWORD get_device_z_depth(IDirect3DDevice *device)
D3DDEVICEDESC *hal_desc, D3DDEVICEDESC *hel_desc, void *ctx)
{ {
DWORD *z_depth = ctx; DDSCAPS caps = {DDSCAPS_ZBUFFER};
IDirectDrawSurface *ds, *rt;
DDSURFACEDESC desc;
HRESULT hr;
if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid)) if (FAILED(IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt)))
return D3DENUMRET_OK; return 0;
if (hal_desc->dwDeviceZBufferBitDepth & DDBD_32) hr = IDirectDrawSurface_GetAttachedSurface(rt, &caps, &ds);
*z_depth = 32; IDirectDrawSurface_Release(rt);
else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24) if (FAILED(hr))
*z_depth = 24; return 0;
else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16)
*z_depth = 16;
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) static IDirectDraw *create_ddraw(void)
...@@ -794,7 +800,6 @@ static void test_coop_level_d3d_state(void) ...@@ -794,7 +800,6 @@ static void test_coop_level_d3d_state(void)
static void test_surface_interface_mismatch(void) static void test_surface_interface_mismatch(void)
{ {
IDirectDraw *ddraw = NULL; IDirectDraw *ddraw = NULL;
IDirect3D *d3d = NULL;
IDirectDrawSurface *surface = NULL, *ds; IDirectDrawSurface *surface = NULL, *ds;
IDirectDrawSurface3 *surface3 = NULL; IDirectDrawSurface3 *surface3 = NULL;
IDirect3DDevice *device = NULL; IDirect3DDevice *device = NULL;
...@@ -817,8 +822,17 @@ static void test_surface_interface_mismatch(void) ...@@ -817,8 +822,17 @@ static void test_surface_interface_mismatch(void)
goto cleanup; goto cleanup;
} }
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); {
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)); memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwSize = sizeof(surface_desc);
...@@ -837,19 +851,6 @@ static void test_surface_interface_mismatch(void) ...@@ -837,19 +851,6 @@ static void test_surface_interface_mismatch(void)
goto cleanup; 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)); memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
...@@ -893,7 +894,6 @@ cleanup: ...@@ -893,7 +894,6 @@ cleanup:
if (surface3) IDirectDrawSurface3_Release(surface3); if (surface3) IDirectDrawSurface3_Release(surface3);
if (surface) IDirectDrawSurface_Release(surface); if (surface) IDirectDrawSurface_Release(surface);
if (device) IDirect3DDevice_Release(device); if (device) IDirect3DDevice_Release(device);
if (d3d) IDirect3D_Release(d3d);
if (ddraw) IDirectDraw_Release(ddraw); if (ddraw) IDirectDraw_Release(ddraw);
DestroyWindow(window); DestroyWindow(window);
} }
...@@ -3186,9 +3186,9 @@ static void test_rt_caps(void) ...@@ -3186,9 +3186,9 @@ static void test_rt_caps(void)
{ {
PALETTEENTRY palette_entries[256]; PALETTEENTRY palette_entries[256];
IDirectDrawPalette *palette; IDirectDrawPalette *palette;
IDirect3DDevice *device;
IDirectDraw *ddraw; IDirectDraw *ddraw;
DWORD z_depth = 0; DWORD z_depth = 0;
IDirect3D *d3d;
unsigned int i; unsigned int i;
ULONG refcount; ULONG refcount;
HWND window; HWND window;
...@@ -3360,22 +3360,16 @@ static void test_rt_caps(void) ...@@ -3360,22 +3360,16 @@ static void test_rt_caps(void)
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0); 0, 0, 640, 480, 0, 0, 0, 0);
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); if (!(device = create_device(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)))
{
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"); skip("Failed to create a 3D device, skipping test.\n");
IDirect3D_Release(d3d); IDirectDraw_Release(ddraw);
goto done; 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)); memset(palette_entries, 0, sizeof(palette_entries));
hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL); hr = IDirectDraw_CreatePalette(ddraw, DDPCAPS_ALLOW256 | DDPCAPS_8BIT, palette_entries, &palette, NULL);
...@@ -3442,9 +3436,6 @@ static void test_rt_caps(void) ...@@ -3442,9 +3436,6 @@ static void test_rt_caps(void)
} }
IDirectDrawPalette_Release(palette); IDirectDrawPalette_Release(palette);
IDirect3D_Release(d3d);
done:
refcount = IDirectDraw_Release(ddraw); refcount = IDirectDraw_Release(ddraw);
ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount); ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
DestroyWindow(window); DestroyWindow(window);
...@@ -3609,8 +3600,8 @@ static void test_primary_caps(void) ...@@ -3609,8 +3600,8 @@ static void test_primary_caps(void)
static void test_surface_lock(void) static void test_surface_lock(void)
{ {
IDirectDraw *ddraw; IDirectDraw *ddraw;
IDirect3D *d3d = NULL;
IDirectDrawSurface *surface; IDirectDrawSurface *surface;
IDirect3DDevice *device;
HRESULT hr; HRESULT hr;
HWND window; HWND window;
unsigned int i; unsigned int i;
...@@ -3662,21 +3653,16 @@ static void test_surface_lock(void) ...@@ -3662,21 +3653,16 @@ static void test_surface_lock(void)
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0); 0, 0, 640, 480, 0, 0, 0, 0);
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); if (!(device = create_device(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)))
{
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"); skip("Failed to create a 3D device, skipping test.\n");
goto done; 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++) for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
{ {
...@@ -3712,10 +3698,6 @@ static void test_surface_lock(void) ...@@ -3712,10 +3698,6 @@ static void test_surface_lock(void)
IDirectDrawSurface_Release(surface); IDirectDrawSurface_Release(surface);
} }
done:
if (d3d)
IDirect3D_Release(d3d);
refcount = IDirectDraw_Release(ddraw); refcount = IDirectDraw_Release(ddraw);
ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount); ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
DestroyWindow(window); DestroyWindow(window);
......
...@@ -140,22 +140,28 @@ static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y) ...@@ -140,22 +140,28 @@ static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y)
return color; return color;
} }
static HRESULT CALLBACK enum_z_fmt(GUID *guid, char *description, char *name, static DWORD get_device_z_depth(IDirect3DDevice2 *device)
D3DDEVICEDESC *hal_desc, D3DDEVICEDESC *hel_desc, void *ctx)
{ {
DWORD *z_depth = ctx; DDSCAPS caps = {DDSCAPS_ZBUFFER};
IDirectDrawSurface *ds, *rt;
DDSURFACEDESC desc;
HRESULT hr;
if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid)) if (FAILED(IDirect3DDevice2_GetRenderTarget(device, &rt)))
return D3DENUMRET_OK; return 0;
if (hal_desc->dwDeviceZBufferBitDepth & DDBD_32) hr = IDirectDrawSurface_GetAttachedSurface(rt, &caps, &ds);
*z_depth = 32; IDirectDrawSurface_Release(rt);
else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_24) if (FAILED(hr))
*z_depth = 24; return 0;
else if (hal_desc->dwDeviceZBufferBitDepth & DDBD_16)
*z_depth = 16;
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) static IDirectDraw2 *create_ddraw(void)
...@@ -780,8 +786,17 @@ static void test_surface_interface_mismatch(void) ...@@ -780,8 +786,17 @@ static void test_surface_interface_mismatch(void)
goto cleanup; goto cleanup;
} }
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr); {
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)); memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwSize = sizeof(surface_desc);
...@@ -806,13 +821,6 @@ static void test_surface_interface_mismatch(void) ...@@ -806,13 +821,6 @@ static void test_surface_interface_mismatch(void)
goto cleanup; 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)); memset(&surface_desc, 0, sizeof(surface_desc));
surface_desc.dwSize = sizeof(surface_desc); surface_desc.dwSize = sizeof(surface_desc);
surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT;
...@@ -3776,6 +3784,7 @@ static void test_rt_caps(void) ...@@ -3776,6 +3784,7 @@ static void test_rt_caps(void)
{ {
PALETTEENTRY palette_entries[256]; PALETTEENTRY palette_entries[256];
IDirectDrawPalette *palette; IDirectDrawPalette *palette;
IDirect3DDevice2 *device;
IDirectDraw2 *ddraw; IDirectDraw2 *ddraw;
DWORD z_depth = 0; DWORD z_depth = 0;
IDirect3D2 *d3d; IDirect3D2 *d3d;
...@@ -3992,20 +4001,20 @@ static void test_rt_caps(void) ...@@ -3992,20 +4001,20 @@ static void test_rt_caps(void)
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0); 0, 0, 640, 480, 0, 0, 0, 0);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); if (!(device = create_device(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)))
{ {
skip("D3D interface is not available, skipping test.\n"); skip("Failed to create a 3D device, skipping test.\n");
goto done; 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);
hr = IDirect3D2_EnumDevices(d3d, enum_z_fmt, &z_depth); if (FAILED(hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d)))
if (FAILED(hr) || !z_depth)
{ {
skip("No depth buffer formats available, skipping test.\n"); skip("D3D interface is not available, skipping test.\n");
IDirect3D2_Release(d3d);
goto done; goto done;
} }
...@@ -4297,8 +4306,8 @@ static void test_primary_caps(void) ...@@ -4297,8 +4306,8 @@ static void test_primary_caps(void)
static void test_surface_lock(void) static void test_surface_lock(void)
{ {
IDirectDraw2 *ddraw; IDirectDraw2 *ddraw;
IDirect3D2 *d3d = NULL;
IDirectDrawSurface *surface; IDirectDrawSurface *surface;
IDirect3DDevice2 *device;
HRESULT hr; HRESULT hr;
HWND window; HWND window;
unsigned int i; unsigned int i;
...@@ -4350,21 +4359,16 @@ static void test_surface_lock(void) ...@@ -4350,21 +4359,16 @@ static void test_surface_lock(void)
window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW, window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
0, 0, 640, 480, 0, 0, 0, 0); 0, 0, 640, 480, 0, 0, 0, 0);
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); if (!(device = create_device(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)))
{
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"); skip("Failed to create a 3D device, skipping test.\n");
goto done; 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++) for (i = 0; i < sizeof(tests) / sizeof(*tests); i++)
{ {
...@@ -4400,9 +4404,6 @@ static void test_surface_lock(void) ...@@ -4400,9 +4404,6 @@ static void test_surface_lock(void)
IDirectDrawSurface_Release(surface); IDirectDrawSurface_Release(surface);
} }
done:
if (d3d)
IDirect3D2_Release(d3d);
refcount = IDirectDraw2_Release(ddraw); refcount = IDirectDraw2_Release(ddraw);
ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount); ok(refcount == 0, "The ddraw object was not properly freed, refcount %u.\n", refcount);
DestroyWindow(window); DestroyWindow(window);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment