[PATCH 4/4] d3d8/tests: Add a windowed GetFrontBufferData test (v2).
Stefan Dösinger
stefan at codeweavers.com
Fri Jul 17 05:13:20 CDT 2015
Version 2: Skip if the window is obscured.
The d3d8 method is called GetFrontBuffer. I've used the same name as in
d3d9 for consistent test naming.
---
dlls/d3d8/tests/visual.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index 41ef2f9..9f70c4b 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -7885,6 +7885,135 @@ 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};
+ static const struct
+ {
+ unsigned int x, y;
+ D3DCOLOR color;
+ }
+ tests[] =
+ {
+ { 99, 99, 0x00ffffff},
+ {101, 99, 0x00ffffff},
+ { 99, 101, 0x00ffffff},
+ {101, 101, 0x0000ff00},
+
+ {399, 99, 0x00ffffff},
+ {401, 99, 0x00ffffff},
+ {399, 101, 0x0000ff00},
+ {401, 101, 0x00ffffff},
+
+ { 99, 199, 0x00ffffff},
+ {101, 199, 0x0000ff00},
+ { 99, 201, 0x00ffffff},
+ {101, 201, 0x00ffffff},
+
+ {399, 199, 0x0000ff00},
+ {401, 299, 0x00ffffff},
+ {399, 201, 0x00ffffff},
+ {401, 201, 0x00ffffff},
+ };
+ unsigned int i;
+
+ 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);
+
+ for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
+ {
+ POINT p = {tests[i].x + offset.x, tests[i].y + offset.y};
+
+ if (ChildWindowFromPoint(GetDesktopWindow(), p) != window)
+ {
+ skip("Window is covered by another window, skipping GetFrontBufferData test.\n");
+ break;
+ }
+
+ color = get_pixel_color_from_surface(surface, p.x, p.y);
+ ok(color_match(color, tests[i].color, 1), "Got color 0x%08x, expected 0x%08x, test %u, %ux%u.\n",
+ color, tests[i].color, i, p.x, p.y);
+ }
+
+ 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;
@@ -7946,4 +8075,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