[PATCH 05/10] ddraw/tests: Add some tests to show that we should maintain D3D state across cooperative level chnages.
Henri Verbeet
hverbeet at codeweavers.com
Tue Jan 17 14:13:34 CST 2012
---
dlls/ddraw/tests/ddraw1.c | 229 +++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw2.c | 247 +++++++++++++++++++++++++++++++++++++++++++++
dlls/ddraw/tests/ddraw4.c | 143 ++++++++++++++++++++++++++-
dlls/ddraw/tests/ddraw7.c | 117 +++++++++++++++++++++-
4 files changed, 734 insertions(+), 2 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 7ba5de1..d9620d2 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -54,6 +54,24 @@ 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)
+{
+ DWORD *z_depth = ctx;
+
+ if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid))
+ return D3DENUMRET_OK;
+
+ 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;
+
+ return DDENUMRET_OK;
+}
+
static IDirectDraw *create_ddraw(void)
{
IDirectDraw *ddraw;
@@ -64,6 +82,104 @@ static IDirectDraw *create_ddraw(void)
return ddraw;
}
+static IDirect3DDevice *create_device(IDirectDraw *ddraw, HWND window, DWORD coop_level)
+{
+ IDirectDrawSurface *surface, *ds;
+ IDirect3DDevice *device = NULL;
+ DDSURFACEDESC surface_desc;
+ DWORD z_depth = 0;
+ IDirect3D *d3d;
+ HRESULT hr;
+
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, coop_level);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ memset(&surface_desc, 0, sizeof(surface_desc));
+ surface_desc.dwSize = sizeof(surface_desc);
+ surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+ surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
+ surface_desc.dwWidth = 640;
+ surface_desc.dwHeight = 480;
+
+ hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+ ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+ if (coop_level & DDSCL_NORMAL)
+ {
+ IDirectDrawClipper *clipper;
+
+ hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL);
+ ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
+ hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
+ ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
+ hr = IDirectDrawSurface_SetClipper(surface, clipper);
+ ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
+ IDirectDrawClipper_Release(clipper);
+ }
+
+ hr = IDirectDraw_QueryInterface(ddraw, &IID_IDirect3D, (void **)&d3d);
+ if (FAILED(hr))
+ {
+ IDirectDrawSurface_Release(surface);
+ return NULL;
+ }
+
+ 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;
+ }
+
+ 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;
+ 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;
+ }
+
+ 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;
+ }
+
+ hr = IDirectDrawSurface_QueryInterface(surface, &IID_IDirect3DHALDevice, (void **)&device);
+ IDirectDrawSurface_Release(surface);
+ if (FAILED(hr))
+ return NULL;
+
+ return device;
+}
+
+static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
+{
+ HRESULT hr = IDirectDrawSurface_Restore(surface);
+ ok(SUCCEEDED(hr), "Failed to restore surface, hr %#x.\n", hr);
+ IDirectDrawSurface_Release(surface);
+
+ return DDENUMRET_OK;
+}
+
+static HRESULT restore_surfaces(IDirectDraw *ddraw)
+{
+ return IDirectDraw_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
+ NULL, NULL, restore_callback);
+}
+
static void test_coop_level_create_device_window(void)
{
HWND focus_window, device_window;
@@ -360,8 +476,121 @@ static void test_clipper_blt(void)
IDirectDraw_Release(ddraw);
}
+static void test_coop_level_d3d_state(void)
+{
+ D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
+ D3DMATERIALHANDLE background_handle;
+ IDirectDrawSurface *rt, *surface;
+ IDirect3DMaterial *background;
+ IDirect3DViewport *viewport;
+ IDirect3DDevice *device;
+ D3DMATERIAL material;
+ IDirectDraw *ddraw;
+ D3DVIEWPORT vp;
+ IDirect3D *d3d;
+ D3DCOLOR color;
+ HWND window;
+ HRESULT hr;
+
+ window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+ 0, 0, 640, 480, 0, 0, 0, 0);
+ if (!(ddraw = create_ddraw()))
+ {
+ skip("Failed to create ddraw object, skipping test.\n");
+ DestroyWindow(window);
+ return;
+ }
+ if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create D3D device, skipping test.\n");
+ IDirectDraw_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice_GetDirect3D(device, &d3d);
+ ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
+ hr = IDirect3D_CreateViewport(d3d, &viewport, NULL);
+ ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
+ hr = IDirect3D_CreateMaterial(d3d, &background, NULL);
+ ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
+ IDirect3D_Release(d3d);
+
+ hr = IDirect3DDevice_AddViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
+ memset(&vp, 0, sizeof(vp));
+ vp.dwSize = sizeof(vp);
+ vp.dwX = 0;
+ vp.dwY = 0;
+ vp.dwWidth = 640;
+ vp.dwHeight = 480;
+ vp.dvScaleX = 320.0f;
+ vp.dvScaleY = 240.0f;
+ vp.dvMaxX = 1.0f;
+ vp.dvMaxY = 1.0f;
+ vp.dvMinZ = 0.0f;
+ vp.dvMaxZ = 1.0f;
+ hr = IDirect3DViewport_SetViewport(viewport, &vp);
+ ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
+
+ memset(&material, 0, sizeof(material));
+ material.dwSize = sizeof(material);
+ U1(U(material).diffuse).r = 1.0f;
+ U2(U(material).diffuse).g = 0.0f;
+ U3(U(material).diffuse).b = 0.0f;
+ U4(U(material).diffuse).a = 1.0f;
+ hr = IDirect3DMaterial_SetMaterial(background, &material);
+ ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
+ hr = IDirect3DMaterial_GetHandle(background, device, &background_handle);
+ ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
+ hr = IDirect3DViewport_SetBackground(viewport, background_handle);
+ ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDrawSurface_IsLost(rt);
+ ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+ hr = restore_surfaces(ddraw);
+ ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
+
+ memset(&material, 0, sizeof(material));
+ material.dwSize = sizeof(material);
+ U1(U(material).diffuse).r = 0.0f;
+ U2(U(material).diffuse).g = 1.0f;
+ U3(U(material).diffuse).b = 0.0f;
+ U4(U(material).diffuse).a = 1.0f;
+ hr = IDirect3DMaterial_SetMaterial(background, &material);
+ ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice_QueryInterface(device, &IID_IDirectDrawSurface, (void **)&surface);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ ok(surface == rt, "Got unexpected surface %p.\n", surface);
+ hr = IDirect3DViewport_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ todo_wine ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirect3DDevice_DeleteViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
+ IDirect3DMaterial_Release(background);
+ IDirect3DViewport_Release(viewport);
+ IDirectDrawSurface_Release(surface);
+ IDirectDrawSurface_Release(rt);
+ IDirect3DDevice_Release(device);
+ IDirectDraw_Release(ddraw);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw1)
{
test_coop_level_create_device_window();
test_clipper_blt();
+ test_coop_level_d3d_state();
}
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index a0a26ee..f6b5538 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -54,6 +54,24 @@ 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)
+{
+ DWORD *z_depth = ctx;
+
+ if (!IsEqualGUID(&IID_IDirect3DHALDevice, guid))
+ return D3DENUMRET_OK;
+
+ 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;
+
+ return DDENUMRET_OK;
+}
+
static IDirectDraw2 *create_ddraw(void)
{
IDirectDraw2 *ddraw2;
@@ -71,6 +89,107 @@ static IDirectDraw2 *create_ddraw(void)
return ddraw2;
}
+static IDirect3DDevice2 *create_device(IDirectDraw2 *ddraw, HWND window, DWORD coop_level)
+{
+ IDirectDrawSurface *surface, *ds;
+ IDirect3DDevice2 *device = NULL;
+ DDSURFACEDESC surface_desc;
+ DWORD z_depth = 0;
+ IDirect3D2 *d3d;
+ HRESULT hr;
+
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, coop_level);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+ memset(&surface_desc, 0, sizeof(surface_desc));
+ surface_desc.dwSize = sizeof(surface_desc);
+ surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
+ surface_desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
+ surface_desc.dwWidth = 640;
+ surface_desc.dwHeight = 480;
+
+ hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+ ok(SUCCEEDED(hr), "Failed to create surface, hr %#x.\n", hr);
+
+ if (coop_level & DDSCL_NORMAL)
+ {
+ IDirectDrawClipper *clipper;
+
+ hr = IDirectDraw2_CreateClipper(ddraw, 0, &clipper, NULL);
+ ok(SUCCEEDED(hr), "Failed to create clipper, hr %#x.\n", hr);
+ hr = IDirectDrawClipper_SetHWnd(clipper, 0, window);
+ ok(SUCCEEDED(hr), "Failed to set clipper window, hr %#x.\n", hr);
+ hr = IDirectDrawSurface_SetClipper(surface, clipper);
+ ok(SUCCEEDED(hr), "Failed to set surface clipper, hr %#x.\n", hr);
+ IDirectDrawClipper_Release(clipper);
+ }
+
+ hr = IDirectDraw2_QueryInterface(ddraw, &IID_IDirect3D2, (void **)&d3d);
+ if (FAILED(hr))
+ {
+ IDirectDrawSurface_Release(surface);
+ 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)
+ {
+ 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;
+ 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))
+ {
+ IDirect3D2_Release(d3d);
+ IDirectDrawSurface_Release(surface);
+ return NULL;
+ }
+
+ hr = IDirect3D2_CreateDevice(d3d, &IID_IDirect3DHALDevice, surface, &device);
+ IDirect3D2_Release(d3d);
+ IDirectDrawSurface_Release(surface);
+ if (FAILED(hr))
+ return NULL;
+
+ return device;
+}
+
+static HRESULT CALLBACK restore_callback(IDirectDrawSurface *surface, DDSURFACEDESC *desc, void *context)
+{
+ HRESULT hr = IDirectDrawSurface_Restore(surface);
+ ok(SUCCEEDED(hr), "Failed to restore surface, hr %#x.\n", hr);
+ IDirectDrawSurface_Release(surface);
+
+ return DDENUMRET_OK;
+}
+
+static HRESULT restore_surfaces(IDirectDraw2 *ddraw)
+{
+ return IDirectDraw2_EnumSurfaces(ddraw, DDENUMSURFACES_ALL | DDENUMSURFACES_DOESEXIST,
+ NULL, NULL, restore_callback);
+}
+
static void test_coop_level_create_device_window(void)
{
HWND focus_window, device_window;
@@ -367,8 +486,136 @@ static void test_clipper_blt(void)
IDirectDraw2_Release(ddraw);
}
+static void test_coop_level_d3d_state(void)
+{
+ D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
+ D3DMATERIALHANDLE background_handle;
+ IDirectDrawSurface *rt, *surface;
+ IDirect3DMaterial2 *background;
+ IDirect3DViewport2 *viewport;
+ IDirect3DDevice2 *device;
+ D3DMATERIAL material;
+ IDirectDraw2 *ddraw;
+ D3DVIEWPORT2 vp;
+ IDirect3D2 *d3d;
+ D3DCOLOR color;
+ DWORD value;
+ HWND window;
+ HRESULT hr;
+
+ window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+ 0, 0, 640, 480, 0, 0, 0, 0);
+ if (!(ddraw = create_ddraw()))
+ {
+ skip("Failed to create ddraw object, skipping test.\n");
+ DestroyWindow(window);
+ return;
+ }
+ if (!(device = create_device(ddraw, window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create D3D device, skipping test.\n");
+ IDirectDraw2_Release(ddraw);
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice2_GetDirect3D(device, &d3d);
+ ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
+ hr = IDirect3D2_CreateViewport(d3d, &viewport, NULL);
+ ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
+ hr = IDirect3D2_CreateMaterial(d3d, &background, NULL);
+ ok(SUCCEEDED(hr), "Failed to create material, hr %#x.\n", hr);
+ IDirect3D2_Release(d3d);
+
+ hr = IDirect3DDevice2_AddViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
+ memset(&vp, 0, sizeof(vp));
+ vp.dwSize = sizeof(vp);
+ vp.dwX = 0;
+ vp.dwY = 0;
+ vp.dwWidth = 640;
+ vp.dwHeight = 480;
+ vp.dvClipX = -1.0f;
+ vp.dvClipY = 1.0f;
+ vp.dvClipWidth = 2.0f;
+ vp.dvClipHeight = 2.0f;
+ vp.dvMinZ = 0.0f;
+ vp.dvMaxZ = 1.0f;
+ hr = IDirect3DViewport2_SetViewport2(viewport, &vp);
+ ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
+
+ memset(&material, 0, sizeof(material));
+ material.dwSize = sizeof(material);
+ U1(U(material).diffuse).r = 1.0f;
+ U2(U(material).diffuse).g = 0.0f;
+ U3(U(material).diffuse).b = 0.0f;
+ U4(U(material).diffuse).a = 1.0f;
+ hr = IDirect3DMaterial2_SetMaterial(background, &material);
+ ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
+ hr = IDirect3DMaterial2_GetHandle(background, device, &background_handle);
+ ok(SUCCEEDED(hr), "Failed to get material handle, hr %#x.\n", hr);
+ hr = IDirect3DViewport2_SetBackground(viewport, background_handle);
+ ok(SUCCEEDED(hr), "Failed to set viewport background, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice2_GetRenderTarget(device, &rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ hr = IDirect3DDevice2_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(!!value, "Got unexpected z-enable state %#x.\n", value);
+ hr = IDirect3DDevice2_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
+ hr = IDirect3DDevice2_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+ ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
+ hr = IDirect3DViewport2_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirectDraw2_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDrawSurface_IsLost(rt);
+ ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+ hr = restore_surfaces(ddraw);
+ ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
+
+ memset(&material, 0, sizeof(material));
+ material.dwSize = sizeof(material);
+ U1(U(material).diffuse).r = 0.0f;
+ U2(U(material).diffuse).g = 1.0f;
+ U3(U(material).diffuse).b = 0.0f;
+ U4(U(material).diffuse).a = 1.0f;
+ hr = IDirect3DMaterial2_SetMaterial(background, &material);
+ ok(SUCCEEDED(hr), "Failed to set material data, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice2_GetRenderTarget(device, &surface);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ ok(surface == rt, "Got unexpected surface %p.\n", surface);
+ hr = IDirect3DDevice2_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ todo_wine ok(!!value, "Got unexpected z-enable state %#x.\n", value);
+ hr = IDirect3DDevice2_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ todo_wine ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
+ hr = IDirect3DViewport2_Clear(viewport, 1, &clear_rect, D3DCLEAR_TARGET);
+ ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ todo_wine ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirect3DDevice2_DeleteViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
+ IDirect3DMaterial2_Release(background);
+ IDirect3DViewport2_Release(viewport);
+ IDirectDrawSurface_Release(surface);
+ IDirectDrawSurface_Release(rt);
+ IDirect3DDevice2_Release(device);
+ IDirectDraw2_Release(ddraw);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw2)
{
test_coop_level_create_device_window();
test_clipper_blt();
+ test_coop_level_d3d_state();
}
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index bf81412..9e263fe 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -89,6 +89,16 @@ static D3DCOLOR get_surface_color(IDirectDrawSurface4 *surface, UINT x, UINT y)
return color;
}
+static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
+{
+ DDPIXELFORMAT *z_fmt = ctx;
+
+ if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
+ *z_fmt = *format;
+
+ return DDENUMRET_OK;
+}
+
static IDirectDraw4 *create_ddraw(void)
{
IDirectDraw4 *ddraw4;
@@ -108,10 +118,11 @@ static IDirectDraw4 *create_ddraw(void)
static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
{
+ IDirectDrawSurface4 *surface, *ds;
IDirect3DDevice3 *device = NULL;
- IDirectDrawSurface4 *surface;
DDSURFACEDESC2 surface_desc;
IDirectDraw4 *ddraw4;
+ DDPIXELFORMAT z_fmt;
IDirect3D3 *d3d3;
HRESULT hr;
@@ -152,6 +163,41 @@ static IDirect3DDevice3 *create_device(HWND window, DWORD coop_level)
return NULL;
}
+ memset(&z_fmt, 0, sizeof(z_fmt));
+ hr = IDirect3D3_EnumZBufferFormats(d3d3, &IID_IDirect3DHALDevice, enum_z_fmt, &z_fmt);
+ if (FAILED(hr) || !z_fmt.dwSize)
+ {
+ IDirect3D3_Release(d3d3);
+ IDirectDrawSurface4_Release(surface);
+ return NULL;
+ }
+
+ memset(&surface_desc, 0, sizeof(surface_desc));
+ surface_desc.dwSize = sizeof(surface_desc);
+ surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
+ surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
+ U4(surface_desc).ddpfPixelFormat = z_fmt;
+ surface_desc.dwWidth = 640;
+ surface_desc.dwHeight = 480;
+ hr = IDirectDraw4_CreateSurface(ddraw4, &surface_desc, &ds, NULL);
+ ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
+ if (FAILED(hr))
+ {
+ IDirect3D3_Release(d3d3);
+ IDirectDrawSurface4_Release(surface);
+ return NULL;
+ }
+
+ hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
+ ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
+ IDirectDrawSurface4_Release(ds);
+ if (FAILED(hr))
+ {
+ IDirect3D3_Release(d3d3);
+ IDirectDrawSurface4_Release(surface);
+ return NULL;
+ }
+
hr = IDirect3D3_CreateDevice(d3d3, &IID_IDirect3DHALDevice, surface, &device, NULL);
IDirect3D3_Release(d3d3);
IDirectDrawSurface4_Release(surface);
@@ -662,9 +708,104 @@ static void test_clipper_blt(void)
IDirectDraw4_Release(ddraw);
}
+static void test_coop_level_d3d_state(void)
+{
+ D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
+ IDirectDrawSurface4 *rt, *surface;
+ IDirect3DViewport3 *viewport;
+ IDirect3DDevice3 *device;
+ IDirectDraw4 *ddraw;
+ D3DVIEWPORT2 vp;
+ IDirect3D3 *d3d;
+ D3DCOLOR color;
+ DWORD value;
+ HWND window;
+ HRESULT hr;
+
+ window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+ 0, 0, 640, 480, 0, 0, 0, 0);
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create D3D device, skipping test.\n");
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
+ ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
+
+ hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
+ ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
+ hr = IDirect3DDevice3_AddViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
+ memset(&vp, 0, sizeof(vp));
+ vp.dwSize = sizeof(vp);
+ vp.dwX = 0;
+ vp.dwY = 0;
+ vp.dwWidth = 640;
+ vp.dwHeight = 480;
+ vp.dvClipX = -1.0f;
+ vp.dvClipY = 1.0f;
+ vp.dvClipWidth = 2.0f;
+ vp.dvClipHeight = 2.0f;
+ vp.dvMinZ = 0.0f;
+ vp.dvMaxZ = 1.0f;
+ hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
+ ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
+
+ hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(!!value, "Got unexpected z-enable state %#x.\n", value);
+ hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
+ hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+ ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
+ ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
+ ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
+ IDirect3D3_Release(d3d);
+ hr = IDirectDraw4_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDrawSurface4_IsLost(rt);
+ ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+ hr = IDirectDraw4_RestoreAllSurfaces(ddraw);
+ ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
+ IDirectDraw4_Release(ddraw);
+
+ hr = IDirect3DDevice3_GetRenderTarget(device, &surface);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ ok(surface == rt, "Got unexpected surface %p.\n", surface);
+ hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ todo_wine ok(!!value, "Got unexpected z-enable state %#x.\n", value);
+ hr = IDirect3DDevice3_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ todo_wine ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
+ hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
+ ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ todo_wine ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirect3DDevice3_DeleteViewport(device, viewport);
+ ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
+ IDirect3DViewport3_Release(viewport);
+ IDirectDrawSurface4_Release(surface);
+ IDirectDrawSurface4_Release(rt);
+ IDirect3DDevice3_Release(device);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw4)
{
test_process_vertices();
test_coop_level_create_device_window();
test_clipper_blt();
+ test_coop_level_d3d_state();
}
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 84bae12..51fd618 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -99,6 +99,16 @@ static D3DCOLOR get_surface_color(IDirectDrawSurface7 *surface, UINT x, UINT y)
return color;
}
+static HRESULT CALLBACK enum_z_fmt(DDPIXELFORMAT *format, void *ctx)
+{
+ DDPIXELFORMAT *z_fmt = ctx;
+
+ if (U1(*format).dwZBufferBitDepth > U1(*z_fmt).dwZBufferBitDepth)
+ *z_fmt = *format;
+
+ return DDENUMRET_OK;
+}
+
static IDirectDraw7 *create_ddraw(void)
{
IDirectDraw7 *ddraw;
@@ -111,9 +121,10 @@ static IDirectDraw7 *create_ddraw(void)
static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
{
+ IDirectDrawSurface7 *surface, *ds;
IDirect3DDevice7 *device = NULL;
- IDirectDrawSurface7 *surface;
DDSURFACEDESC2 surface_desc;
+ DDPIXELFORMAT z_fmt;
IDirectDraw7 *ddraw;
IDirect3D7 *d3d7;
HRESULT hr;
@@ -155,6 +166,41 @@ static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
return NULL;
}
+ memset(&z_fmt, 0, sizeof(z_fmt));
+ hr = IDirect3D7_EnumZBufferFormats(d3d7, &IID_IDirect3DTnLHalDevice, enum_z_fmt, &z_fmt);
+ if (FAILED(hr) || !z_fmt.dwSize)
+ {
+ IDirect3D7_Release(d3d7);
+ IDirectDrawSurface7_Release(surface);
+ return NULL;
+ }
+
+ memset(&surface_desc, 0, sizeof(surface_desc));
+ surface_desc.dwSize = sizeof(surface_desc);
+ surface_desc.dwFlags = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT;
+ surface_desc.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
+ U4(surface_desc).ddpfPixelFormat = z_fmt;
+ surface_desc.dwWidth = 640;
+ surface_desc.dwHeight = 480;
+ hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &ds, NULL);
+ ok(SUCCEEDED(hr), "Failed to create depth buffer, hr %#x.\n", hr);
+ if (FAILED(hr))
+ {
+ IDirect3D7_Release(d3d7);
+ IDirectDrawSurface7_Release(surface);
+ return NULL;
+ }
+
+ hr = IDirectDrawSurface_AddAttachedSurface(surface, ds);
+ ok(SUCCEEDED(hr), "Failed to attach depth buffer, hr %#x.\n", hr);
+ IDirectDrawSurface7_Release(ds);
+ if (FAILED(hr))
+ {
+ IDirect3D7_Release(d3d7);
+ IDirectDrawSurface7_Release(surface);
+ return NULL;
+ }
+
hr = IDirect3D7_CreateDevice(d3d7, &IID_IDirect3DTnLHalDevice, surface, &device);
IDirect3D7_Release(d3d7);
IDirectDrawSurface7_Release(surface);
@@ -655,6 +701,74 @@ static void test_clipper_blt(void)
IDirectDraw7_Release(ddraw);
}
+static void test_coop_level_d3d_state(void)
+{
+ IDirectDrawSurface7 *rt, *surface;
+ IDirect3DDevice7 *device;
+ IDirectDraw7 *ddraw;
+ IDirect3D7 *d3d;
+ D3DCOLOR color;
+ DWORD value;
+ HWND window;
+ HRESULT hr;
+
+ window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
+ 0, 0, 640, 480, 0, 0, 0, 0);
+ if (!(device = create_device(window, DDSCL_NORMAL)))
+ {
+ skip("Failed to create D3D device, skipping test.\n");
+ DestroyWindow(window);
+ return;
+ }
+
+ hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(!!value, "Got unexpected z-enable state %#x.\n", value);
+ hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
+ hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
+ ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
+ ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
+
+ hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
+ ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
+ hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
+ ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
+ IDirect3D7_Release(d3d);
+ hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
+ ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ hr = IDirectDrawSurface7_IsLost(rt);
+ ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+ hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
+ ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
+ IDirectDraw7_Release(ddraw);
+
+ hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
+ ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ ok(surface == rt, "Got unexpected surface %p.\n", surface);
+ hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ todo_wine ok(!!value, "Got unexpected z-enable state %#x.\n", value);
+ hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
+ ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ todo_wine ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
+ hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
+ ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
+ color = get_surface_color(rt, 320, 240);
+ todo_wine ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
+
+ IDirectDrawSurface7_Release(surface);
+ IDirectDrawSurface7_Release(rt);
+ IDirect3DDevice7_Release(device);
+ DestroyWindow(window);
+}
+
START_TEST(ddraw7)
{
HMODULE module = GetModuleHandleA("ddraw.dll");
@@ -668,4 +782,5 @@ START_TEST(ddraw7)
test_process_vertices();
test_coop_level_create_device_window();
test_clipper_blt();
+ test_coop_level_d3d_state();
}
--
1.7.3.4
More information about the wine-patches
mailing list