Module: wine Branch: master Commit: 66aa4dcc6c76f2046b07bbd8ba4a5baa6fefca0b URL: http://source.winehq.org/git/wine.git/?a=commit;h=66aa4dcc6c76f2046b07bbd8ba...
Author: Henri Verbeet hverbeet@codeweavers.com Date: Fri Feb 28 11:26:53 2014 +0100
ddraw/tests: Don't trust what EnumDevices() tells us about the supported Z buffer formats.
---
dlls/ddraw/tests/ddraw1.c | 63 +++++++++++++++++---------------------------- dlls/ddraw/tests/ddraw2.c | 59 +++++++++++++++++------------------------- 2 files changed, 47 insertions(+), 75 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c index 2cc6518..9f45f40 100644 --- a/dlls/ddraw/tests/ddraw1.c +++ b/dlls/ddraw/tests/ddraw1.c @@ -238,11 +238,11 @@ static IDirectDraw *create_ddraw(void)
static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level) { + static const DWORD z_depths[] = {32, 24, 16}; IDirectDrawSurface *surface, *ds; IDirect3DDevice *device = NULL; DDSURFACEDESC surface_desc; - DWORD z_depth = 0; - IDirect3D *d3d; + unsigned int i; HRESULT hr;
hr = IDirectDraw_SetCooperativeLevel(ddraw, window, coop_level); @@ -271,51 +271,34 @@ static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coo IDirectDrawClipper_Release(clipper); }
- hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d); - if (FAILED(hr)) + /* We used to use EnumDevices() for this, but it seems + * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual + * relationship with reality. */ + for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i) { - IDirectDrawSurface_Release(surface); - return NULL; - } + memset(&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; + surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER; + U2(surface_desc).dwZBufferBitDepth = z_depths[i]; + surface_desc.dwWidth = 640; + surface_desc.dwHeight = 480; + if (FAILED(hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL))) + continue;
- hr = IDirect3D_EnumDevices(d3d, enum_z_fmt, &z_depth); - ok(SUCCEEDED(hr), "Failed to enumerate z-formats, hr %#x.\n", hr); - IDirect3D_Release(d3d); - if (FAILED(hr) || !z_depth) - { - IDirectDrawSurface_Release(surface); - return NULL; - } + hr = IDirectDrawSurface_AddAttachedSurface(surface, ds); + ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr); + IDirectDrawSurface_Release(ds); + if (FAILED(hr)) + continue;
- memset(&surface_desc, 0, sizeof(surface_desc)); - surface_desc.dwSize = sizeof(surface_desc); - surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; - surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER; - U2(surface_desc).dwZBufferBitDepth = z_depth; - surface_desc.dwWidth = 640; - surface_desc.dwHeight = 480; - hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &ds, NULL); - ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr); - if (FAILED(hr)) - { - IDirectDrawSurface_Release(surface); - return NULL; - } + if (SUCCEEDED(hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device))) + break;
- hr = IDirectDrawSurface_AddAttachedSurface(surface, ds); - ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr); - IDirectDrawSurface_Release(ds); - if (FAILED(hr)) - { - IDirectDrawSurface_Release(surface); - return NULL; + IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds); }
- hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device); IDirectDrawSurface_Release(surface); - if (FAILED(hr)) - return NULL; - return device; }
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c index 6b34912..ab6c967 100644 --- a/dlls/ddraw/tests/ddraw2.c +++ b/dlls/ddraw/tests/ddraw2.c @@ -177,11 +177,12 @@ static IDirectDraw2 *create_ddraw(void)
static IDirect3DDevice2 *create_device(IDirectDraw2 *ddraw, HWND window, DWORD coop_level) { + static const DWORD z_depths[] = {32, 24, 16}; IDirectDrawSurface *surface, *ds; IDirect3DDevice2 *device = NULL; DDSURFACEDESC surface_desc; - DWORD z_depth = 0; IDirect3D2 *d3d; + unsigned int i; HRESULT hr;
hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, coop_level); @@ -217,47 +218,35 @@ static IDirect3DDevice2 *create_device(IDirectDraw2 *ddraw, HWND window, DWORD c return NULL; }
- hr = IDirect3D2_EnumDevices(d3d, enum_z_fmt, &z_depth); - ok(SUCCEEDED(hr), "Failed to enumerate z-formats, hr %#x.\n", hr); - if (FAILED(hr) || !z_depth) + /* We used to use EnumDevices() for this, but it seems + * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual + * relationship with reality. */ + for (i = 0; i < sizeof(z_depths) / sizeof(*z_depths); ++i) { - IDirect3D2_Release(d3d); - IDirectDrawSurface_Release(surface); - return NULL; - } + memset(&surface_desc, 0, sizeof(surface_desc)); + surface_desc.dwSize = sizeof(surface_desc); + surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; + surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER; + U2(surface_desc).dwZBufferBitDepth = z_depths[i]; + surface_desc.dwWidth = 640; + surface_desc.dwHeight = 480; + if (FAILED(hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &ds, NULL))) + continue;
- memset(&surface_desc, 0, sizeof(surface_desc)); - surface_desc.dwSize = sizeof(surface_desc); - surface_desc.dwFlags = DDSD_CAPS | DDSD_ZBUFFERBITDEPTH | DDSD_WIDTH | DDSD_HEIGHT; - surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER; - U2(surface_desc).dwZBufferBitDepth = z_depth; - surface_desc.dwWidth = 640; - surface_desc.dwHeight = 480; - hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &ds, NULL); - ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr); - if (FAILED(hr)) - { - IDirect3D2_Release(d3d); - IDirectDrawSurface_Release(surface); - return NULL; - } + hr = IDirectDrawSurface_AddAttachedSurface(surface, ds); + ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr); + IDirectDrawSurface_Release(ds); + if (FAILED(hr)) + continue;
- hr = IDirectDrawSurface_AddAttachedSurface(surface, ds); - ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr); - IDirectDrawSurface_Release(ds); - if (FAILED(hr)) - { - IDirect3D2_Release(d3d); - IDirectDrawSurface_Release(surface); - return NULL; + if (SUCCEEDED(hr = IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device))) + break; + + IDirectDrawSurface_DeleteAttachedSurface(surface, 0, ds); }
- hr = IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device); IDirect3D2_Release(d3d); IDirectDrawSurface_Release(surface); - if (FAILED(hr)) - return NULL; - return device; }