[PATCH 2/4] d3d8/tests: Add a windowed GetFrontBufferData test.

Stefan Dösinger stefan at codeweavers.com
Mon Jul 6 16:47:26 CDT 2015


The d3d8 method is called GetFrontBuffer. I've used the same name as in
d3d9 for consistent test naming.
---
 dlls/d3d8/tests/visual.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)

diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index da20b84..dba7c1c 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -7555,6 +7555,128 @@ done:
     DestroyWindow(window);
 }
 
+/* Locks a given surface and returns the color at (x,y).  It's the caller's
+ * responsibility to only pass in lockable surfaces and valid x,y coordinates */
+static DWORD get_pixel_color_from_surface(IDirect3DSurface8 *surface, UINT x, UINT y)
+{
+    DWORD color;
+    HRESULT hr;
+    D3DSURFACE_DESC desc;
+    RECT rect_to_lock = {x, y, x+1, y+1};
+    D3DLOCKED_RECT lr;
+
+    hr = IDirect3DSurface8_GetDesc(surface, &desc);
+    ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
+    hr = IDirect3DSurface8_LockRect(surface, &lr, &rect_to_lock, D3DLOCK_READONLY);
+    ok(SUCCEEDED(hr), "Failed to lock surface, hr %#x.\n", hr);
+
+    switch(desc.Format)
+    {
+        case D3DFMT_A8R8G8B8:
+            color = ((DWORD *)lr.pBits)[0];
+            break;
+
+        default:
+            trace("Error: unknown surface format: %u\n", desc.Format);
+            color = 0xdeadbeef;
+            break;
+    }
+    hr = IDirect3DSurface8_UnlockRect(surface);
+    ok(SUCCEEDED(hr), "Failed to unlock surface, hr %#x.\n", hr);
+    return color;
+}
+
+static void test_windowed_get_front_buffer_data(void)
+{
+    HRESULT hr;
+    IDirect3DDevice8 *device;
+    IDirect3D8 *d3d;
+    ULONG refcount;
+    HWND window;
+    D3DCOLOR color;
+    IDirect3DSurface8 *surface;
+    static const D3DRECT clear_rect = {100, 100, 400, 200};
+    D3DDISPLAYMODE mode;
+    POINT offset = {0, 0};
+    RECT win_rect = {30, 50, 640 + 30, 480 + 50};
+
+    AdjustWindowRect(&win_rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
+    window = CreateWindowA("static", "d3d8_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+            win_rect.left, win_rect.top, win_rect.right - win_rect.left, win_rect.bottom - win_rect.top,
+            NULL, NULL, NULL, NULL);
+    d3d = Direct3DCreate8(D3D_SDK_VERSION);
+    ok(!!d3d, "Failed to create a D3D object.\n");
+
+    if (!(device = create_device(d3d, window, window, TRUE)))
+    {
+        skip("Failed to create a D3D device, skipping tests.\n");
+        IDirect3D8_Release(d3d);
+        DestroyWindow(window);
+        return;
+    }
+
+    hr = IDirect3DDevice8_GetDisplayMode(device, &mode);
+    ok(SUCCEEDED(hr), "Failed to get display mode, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_CreateImageSurface(device, mode.Width, mode.Height,
+            D3DFMT_A8R8G8B8, &surface);
+    ok(SUCCEEDED(hr), "Failed to create readback surface, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice8_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0x00ffffff, 0.0f, 0);
+    ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_Clear(device, 1, &clear_rect, D3DCLEAR_TARGET, 0x0000ff00, 0.0f, 0);
+    ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr);
+    hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
+    ok(SUCCEEDED(hr), "Failed to present, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice8_GetFrontBuffer(device, surface);
+    ok(SUCCEEDED(hr), "Failed to get front buffer data, hr %#x.\n", hr);
+
+    ClientToScreen(window, &offset);
+
+    color = get_pixel_color_from_surface(surface, 99 + offset.x, 99 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 101 + offset.x, 99 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 99 + offset.x, 101 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 101 + offset.x, 101 + offset.y);
+    ok(color_match(color, 0x0000ff00, 1), "Got color 0x%08x.\n", color);
+
+    color = get_pixel_color_from_surface(surface, 399 + offset.x, 99 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 401 + offset.x, 99 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 399 + offset.x, 101 + offset.y);
+    ok(color_match(color, 0x0000ff00, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 401 + offset.x, 101 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+
+    color = get_pixel_color_from_surface(surface, 99 + offset.x, 199 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 101 + offset.x, 199 + offset.y);
+    ok(color_match(color, 0x0000ff00, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 99 + offset.x, 201 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 101 + offset.x, 201 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+
+    color = get_pixel_color_from_surface(surface, 399 + offset.x, 199 + offset.y);
+    ok(color_match(color, 0x0000ff00, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 401 + offset.x, 199 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 399 + offset.x, 201 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+    color = get_pixel_color_from_surface(surface, 401 + offset.x, 201 + offset.y);
+    ok(color_match(color, 0x00ffffff, 1), "Got color 0x%08x.\n", color);
+
+    IDirect3DSurface8_Release(surface);
+
+    refcount = IDirect3DDevice8_Release(device);
+    ok(!refcount, "Device has %u references left.\n", refcount);
+    IDirect3D8_Release(d3d);
+    DestroyWindow(window);
+}
+
 START_TEST(visual)
 {
     D3DADAPTER_IDENTIFIER8 identifier;
@@ -7615,4 +7737,5 @@ START_TEST(visual)
     test_texcoordindex();
     test_vshader_input();
     test_fixed_function_fvf();
+    test_windowed_get_front_buffer_data();
 }
-- 
2.3.6




More information about the wine-patches mailing list