[PATCH 8/8] d3d9/tests: Port test_flip to d3d9.

Stefan Dösinger stefan at codeweavers.com
Mon Sep 14 12:17:52 CDT 2015


This only tests cycling through the backbuffers. Like it's ddraw
counterpart it doesn't test for the front buffer to come out at the
other end of the flip chain. I don't think we want to bother about this
until we have an application that really needs this.

A d3d8 version of this test will follow. Partial presents (RECT or
region parameters in Present) are only valid if the swap effect is COPY.
In this case the back buffer count is forced to be 1 and no buffer
cycling, flipping etc will happen. A test for that will follow.
---
 dlls/d3d9/tests/visual.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c
index d49d3b2..07456f2 100644
--- a/dlls/d3d9/tests/visual.c
+++ b/dlls/d3d9/tests/visual.c
@@ -19796,6 +19796,112 @@ done:
     DestroyWindow(window);
 }
 
+static void test_flip(void)
+{
+    IDirect3DDevice9 *device;
+    IDirect3D9 *d3d;
+    ULONG refcount;
+    HWND window;
+    HRESULT hr;
+    IDirect3DSurface9 *back_buffers[3], *test_surface;
+    unsigned int i;
+    D3DCOLOR color;
+    D3DPRESENT_PARAMETERS present_parameters = {0};
+
+    window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, NULL, NULL, NULL, NULL);
+    d3d = Direct3DCreate9(D3D_SDK_VERSION);
+    ok(!!d3d, "Failed to create a D3D object.\n");
+
+    present_parameters.BackBufferWidth = 640;
+    present_parameters.BackBufferHeight = 480;
+    present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8;
+    present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
+    present_parameters.hDeviceWindow = window;
+    present_parameters.Windowed = TRUE;
+    present_parameters.BackBufferCount = 3;
+    present_parameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
+    hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
+            window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device);
+    if (!device)
+    {
+        skip("Failed to create a D3D device, skipping tests.\n");
+        IDirect3D9_Release(d3d);
+        DestroyWindow(window);
+        return;
+    }
+
+    for (i = 0; i < sizeof(back_buffers) / sizeof(*back_buffers); ++i)
+    {
+        hr = IDirect3DDevice9_GetBackBuffer(device, 0, i, D3DBACKBUFFER_TYPE_MONO, &back_buffers[i]);
+        ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
+    }
+    hr = IDirect3DDevice9_GetRenderTarget(device, 0, &test_surface);
+    ok(SUCCEEDED(hr), "Failed to get original render target, hr %#x.\n", hr);
+    ok(test_surface == back_buffers[0], "Expected render target %p, got %p.\n", back_buffers[0], test_surface);
+    IDirect3DSurface9_Release(test_surface);
+
+    hr = IDirect3DDevice9_SetRenderTarget(device, 0, back_buffers[2]);
+    ok(SUCCEEDED(hr), "Failed to get original render target, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice9_ColorFill(device, back_buffers[0], NULL, 0xffff0000);
+    ok(SUCCEEDED(hr), "Failed to color fill, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_ColorFill(device, back_buffers[1], NULL, 0xff00ff00);
+    ok(SUCCEEDED(hr), "Failed to color fill, hr %#x.\n", hr);
+    hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff0000ff, 0.0f, 0);
+    ok(SUCCEEDED(hr), "Failed to clear, hr %#x\n", hr);
+
+    hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+    ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+    /* Render target is unmodified. */
+    hr = IDirect3DDevice9_GetRenderTarget(device, 0, &test_surface);
+    ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+    ok(test_surface == back_buffers[2], "Expected render target %p, got %p.\n", back_buffers[2], test_surface);
+    IDirect3DSurface9_Release(test_surface);
+
+    /* Backbuffer surface pointers are unmodified */
+    for (i = 0; i < sizeof(back_buffers) / sizeof(*back_buffers); ++i)
+    {
+        hr = IDirect3DDevice9_GetBackBuffer(device, 0, i, D3DBACKBUFFER_TYPE_MONO, &test_surface);
+        ok(SUCCEEDED(hr), "Failed to get back buffer, hr %#x.\n", hr);
+        ok(test_surface == back_buffers[i], "Expected back buffer %u = %p, got %p.\n",
+                i, back_buffers[i], test_surface);
+        IDirect3DSurface9_Release(test_surface);
+    }
+
+    /* Contents were changed. */
+    color = getPixelColorFromSurface(back_buffers[0], 1, 1);
+    ok(color == 0xff00ff00, "Expected back buffer 0 color 0xff00ff00, got 0x%08x.\n", color);
+    color = getPixelColorFromSurface(back_buffers[1], 1, 1);
+    ok(color == 0xff0000ff, "Expected back buffer 1 color 0xff0000ff, got 0x%08x.\n", color);
+
+    hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff808080, 0.0f, 0);
+    ok(SUCCEEDED(hr), "Failed to clear, hr %#x\n", hr);
+
+    hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+    ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+    color = getPixelColorFromSurface(back_buffers[0], 1, 1);
+    ok(color == 0xff0000ff, "Expected back buffer 0 color 0xff0000ff, got 0x%08x.\n", color);
+    color = getPixelColorFromSurface(back_buffers[1], 1, 1);
+    ok(color == 0xff808080, "Expected back buffer 1 color 0xff808080, got 0x%08x.\n", color);
+
+    hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
+    ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
+
+    color = getPixelColorFromSurface(back_buffers[0], 1, 1);
+    ok(color == 0xff808080, "Expected back buffer 0 color 0xff808080, got 0x%08x.\n", color);
+
+    for (i = 0; i < sizeof(back_buffers) / sizeof(*back_buffers); ++i)
+        IDirect3DSurface9_Release(back_buffers[i]);
+
+    refcount = IDirect3DDevice9_Release(device);
+    ok(!refcount, "Device has %u references left.\n", refcount);
+    IDirect3D9_Release(d3d);
+    DestroyWindow(window);
+}
+
 START_TEST(visual)
 {
     D3DADAPTER_IDENTIFIER9 identifier;
@@ -19914,4 +20020,5 @@ START_TEST(visual)
     test_vertex_blending();
     test_updatetexture();
     test_depthbias();
+    test_flip();
 }
-- 
2.4.6




More information about the wine-patches mailing list