[PATCH 1/4] ddraw/tests: Port the depth blit test to ddraw7 (try 3)

Stefan Dösinger stefan at codeweavers.com
Mon Jan 30 01:41:57 CST 2012


Try 3: Style issues, typo and nameless union fixes.

Try 2: Use the new ddraw test infrastructure. I'm assuming the idea is
to put all tests in the ddraw*.c files.

Ddraw2 and ddraw4 tests follow. The ddraw1 behavior on Windows is the
same, but I ran into some problems with our executebuffer implementation
that I couldn't figure out yet.
---
 dlls/ddraw/tests/ddraw7.c |  183 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 183 insertions(+), 0 deletions(-)

diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 7564cb8..8eb7098 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -944,6 +944,188 @@ static void test_coop_level_threaded(void)
     destroy_window_thread(&p);
 }
 
+static IDirectDrawSurface7 *get_depth_stencil(IDirect3DDevice7 *device)
+{
+    IDirectDrawSurface7 *rt, *ret;
+    DDSCAPS2 caps = {DDSCAPS_ZBUFFER, 0, 0, 0};
+    HRESULT hr;
+
+    hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
+    ok(SUCCEEDED(hr), "Failed to get the render target, hr %#x.\n", hr);
+    hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &ret);
+    ok(SUCCEEDED(hr) || hr == DDERR_NOTFOUND, "Failed to get the z buffer, hr %#x.\n", hr);
+    IDirectDrawSurface7_Release(rt);
+    return ret;
+}
+
+static void test_depth_blit(void)
+{
+    IDirect3DDevice7 *device;
+    static struct
+    {
+        float x, y, z;
+        DWORD color;
+    }
+    quad1[] =
+    {
+        { -1.0,  1.0, 0.50f, 0xff00ff00},
+        {  1.0,  1.0, 0.50f, 0xff00ff00},
+        { -1.0, -1.0, 0.50f, 0xff00ff00},
+        {  1.0, -1.0, 0.50f, 0xff00ff00},
+    };
+    static const D3DCOLOR expected_colors[4][4] =
+    {
+        {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
+        {0x00ff0000, 0x00ff0000, 0x0000ff00, 0x0000ff00},
+        {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
+        {0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00},
+    };
+    DDSURFACEDESC2 ddsd_new, ddsd_existing;
+
+    IDirectDrawSurface7 *ds1, *ds2, *ds3, *rt;
+    RECT src_rect, dst_rect;
+    unsigned int i, j;
+    D3DCOLOR color;
+    HRESULT hr;
+    IDirect3D7 *d3d;
+    IDirectDraw7 *ddraw;
+    DDBLTFX fx;
+    HWND window;
+
+    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_GetDirect3D(device, &d3d);
+    ok(SUCCEEDED(hr), "Failed to get Direct3D7 interface, hr %#x.\n", hr);
+    hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
+    ok(SUCCEEDED(hr), "Failed to get DirectDraw7 interface, hr %#x.\n", hr);
+    IDirect3D7_Release(d3d);
+
+    ds1 = get_depth_stencil(device);
+
+    memset(&ddsd_new, 0, sizeof(ddsd_new));
+    ddsd_new.dwSize = sizeof(ddsd_new);
+    memset(&ddsd_existing, 0, sizeof(ddsd_existing));
+    ddsd_existing.dwSize = sizeof(ddsd_existing);
+    hr = IDirectDrawSurface7_GetSurfaceDesc(ds1, &ddsd_existing);
+    ddsd_new.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+    ddsd_new.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
+    ddsd_new.dwWidth = ddsd_existing.dwWidth;
+    ddsd_new.dwHeight = ddsd_existing.dwHeight;
+    U4(ddsd_new).ddpfPixelFormat = U4(ddsd_existing).ddpfPixelFormat;
+    hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds2, NULL);
+    ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
+    hr = IDirectDraw7_CreateSurface(ddraw, &ddsd_new, &ds3, NULL);
+    ok(SUCCEEDED(hr), "Failed to create a z buffer, hr %#x.\n", hr);
+    IDirectDraw7_Release(ddraw);
+
+    hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZENABLE, D3DZB_TRUE);
+    ok(SUCCEEDED(hr), "Failed to enable z testing, hr %#x.\n", hr);
+    hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ZFUNC, D3DCMP_LESSEQUAL);
+    ok(SUCCEEDED(hr), "Failed to set the z function, hr %#x.\n", hr);
+    hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_LIGHTING, FALSE);
+    ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER, 0, 0.0f, 0);
+    ok(SUCCEEDED(hr), "Failed to clear the z buffer, hr %#x.\n", hr);
+
+    /* Partial blit. */
+    SetRect(&src_rect, 0, 0, 320, 240);
+    SetRect(&dst_rect, 0, 0, 320, 240);
+    hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    /* Different locations. */
+    SetRect(&src_rect, 0, 0, 320, 240);
+    SetRect(&dst_rect, 320, 240, 640, 480);
+    hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    /* Streched. */
+    SetRect(&src_rect, 0, 0, 320, 240);
+    SetRect(&dst_rect, 0, 0, 640, 480);
+    hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    /* Flipped. */
+    SetRect(&src_rect, 0, 480, 640, 0);
+    SetRect(&dst_rect, 0, 0, 640, 480);
+    hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+    ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
+    SetRect(&src_rect, 0, 0, 640, 480);
+    SetRect(&dst_rect, 0, 480, 640, 0);
+    hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+    ok(hr == DDERR_INVALIDRECT, "Got unexpected hr %#x.\n", hr);
+    /* Full, explicit. */
+    SetRect(&src_rect, 0, 0, 640, 480);
+    SetRect(&dst_rect, 0, 0, 640, 480);
+    hr = IDirectDrawSurface7_Blt(ds2, &dst_rect, ds1, &src_rect, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    /* Depth -> color blit: Succeeds on Win7 + Radeon HD 5700, fails on WinXP + Radeon X1600 */
+
+    /* Depth blit inside a BeginScene / EndScene pair */
+    hr = IDirect3DDevice7_BeginScene(device);
+    ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
+    /* From the current depth stencil */
+    hr = IDirectDrawSurface7_Blt(ds2, NULL, ds1, NULL, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    /* To the current depth stencil */
+    hr = IDirectDrawSurface7_Blt(ds1, NULL, ds2, NULL, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    /* Between unbound surfaces */
+    hr = IDirectDrawSurface7_Blt(ds3, NULL, ds2, NULL, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    hr = IDirect3DDevice7_EndScene(device);
+    ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
+
+    /* Avoid changing the depth stencil, it doesn't work properly on Windows.
+     * Instead use DDBLT_DEPTHFILL to clear the depth stencil. Unfortunately
+     * drivers disagree on the meaning of dwFillDepth. Only 0 seems to produce
+     * a reliable result(z = 0.0) */
+    memset(&fx, 0, sizeof(fx));
+    fx.dwSize = sizeof(fx);
+    hr = IDirectDrawSurface7_Blt(ds2, NULL, NULL, NULL, DDBLT_DEPTHFILL | DDBLT_WAIT, &fx);
+    ok(SUCCEEDED(hr), "Failed to clear the source z buffer, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0);
+    ok(SUCCEEDED(hr), "Failed to clear the color and z buffers, hr %#x.\n", hr);
+    SetRect(&dst_rect, 0, 0, 320, 240);
+    hr = IDirectDrawSurface7_Blt(ds1, &dst_rect, ds2, NULL, DDBLT_WAIT, NULL);
+    ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
+    IDirectDrawSurface7_Release(ds3);
+    IDirectDrawSurface7_Release(ds2);
+    IDirectDrawSurface7_Release(ds1);
+
+    hr = IDirect3DDevice7_BeginScene(device);
+    ok(SUCCEEDED(hr), "Failed to start scene, hr %#x.\n", hr);
+    hr = IDirect3DDevice7_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE,
+            quad1, 4, 0);
+    ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
+    hr = IDirect3DDevice7_EndScene(device);
+    ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
+    ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+    for (i = 0; i < 4; ++i)
+    {
+        for (j = 0; j < 4; ++j)
+        {
+            unsigned int x = 80 * ((2 * j) + 1);
+            unsigned int y = 60 * ((2 * i) + 1);
+            color = get_surface_color(rt, x, y);
+            ok(compare_color(color, expected_colors[i][j], 1),
+                    "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected_colors[i][j], x, y, color);
+        }
+    }
+
+    IDirectDrawSurface7_Release(rt);
+    IDirect3DDevice7_Release(device);
+    DestroyWindow(window);
+}
+
 START_TEST(ddraw7)
 {
     HMODULE module = GetModuleHandleA("ddraw.dll");
@@ -960,4 +1142,5 @@ START_TEST(ddraw7)
     test_coop_level_d3d_state();
     test_surface_interface_mismatch();
     test_coop_level_threaded();
+    test_depth_blit();
 }
-- 
1.7.3.4




More information about the wine-patches mailing list