[PATCH 5/6] d3d8/tests: Add helpers to avoid multiple readbacks of the render target surface.
Matteo Bruni
mbruni at codeweavers.com
Wed Oct 7 18:26:45 CDT 2015
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
dlls/d3d8/tests/visual.c | 100 +++++++++++++++++++++++++++++++++++++++++------
1 file changed, 88 insertions(+), 12 deletions(-)
diff --git a/dlls/d3d8/tests/visual.c b/dlls/d3d8/tests/visual.c
index 318d3ca..38e7af0 100644
--- a/dlls/d3d8/tests/visual.c
+++ b/dlls/d3d8/tests/visual.c
@@ -146,6 +146,77 @@ static D3DCOLOR get_surface_color(IDirect3DSurface8 *surface, UINT x, UINT y)
return color;
}
+static D3DLOCKED_RECT get_rt(IDirect3DDevice8 *device, IDirect3DSurface8 **surf)
+{
+ IDirect3DTexture8 *tex = NULL;
+ IDirect3DSurface8 *backbuf = NULL;
+ HRESULT hr;
+ D3DLOCKED_RECT locked_rect = {0};
+
+ *surf = NULL;
+ hr = IDirect3DDevice8_CreateTexture(device, 640, 480, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex);
+ if (FAILED(hr) || !tex)
+ {
+ trace("Can't create an offscreen plain surface to read the render target data, hr %x.\n", hr);
+ return locked_rect;
+ }
+ hr = IDirect3DTexture8_GetSurfaceLevel(tex, 0, surf);
+ if (FAILED(hr))
+ {
+ trace("Can't get surface from texture, hr %x.\n", hr);
+ goto error;
+ }
+ hr = IDirect3DDevice8_GetRenderTarget(device, &backbuf);
+ if (FAILED(hr))
+ {
+ trace("Can't get the render target, hr %x.\n", hr);
+ goto error;
+ }
+ hr = IDirect3DDevice8_CopyRects(device, backbuf, NULL, 0, *surf, NULL);
+ if (FAILED(hr))
+ {
+ trace("Can't read the render target, hr %x.\n", hr);
+ goto error;
+ }
+ hr = IDirect3DSurface8_LockRect(*surf, &locked_rect, NULL, D3DLOCK_READONLY);
+ if (FAILED(hr))
+ {
+ trace("Can't lock the offscreen surface, hr %x.\n", hr);
+ goto error;
+ }
+ IDirect3DSurface8_Release(backbuf);
+ IDirect3DTexture8_Release(tex);
+
+ return locked_rect;
+
+error:
+ if (backbuf)
+ IDirect3DSurface8_Release(backbuf);
+ if (surf)
+ IDirect3DSurface8_Release(*surf);
+ *surf = NULL;
+ if (tex)
+ IDirect3DTexture8_Release(tex);
+ return locked_rect;
+}
+
+static DWORD get_rt_color(D3DLOCKED_RECT *locked_rect, unsigned int x, unsigned int y)
+{
+ return locked_rect->pBits
+ ? ((DWORD *)locked_rect->pBits)[y * locked_rect->Pitch / sizeof(DWORD) + x] : 0xdeadbeef;
+}
+
+static void release_rt(IDirect3DSurface8 *surf)
+{
+ HRESULT hr;
+
+ if (!surf)
+ return;
+ if (FAILED(hr = IDirect3DSurface8_UnlockRect(surf)))
+ trace("Can't unlock the offscreen surface, hr %#x.\n", hr);
+ IDirect3DSurface8_Release(surf);
+}
+
static IDirect3DDevice8 *create_device(IDirect3D8 *d3d, HWND device_window, HWND focus_window, BOOL windowed)
{
D3DPRESENT_PARAMETERS present_parameters = {0};
@@ -7166,31 +7237,36 @@ static void test_pointsize(void)
}
else
{
- color = getPixelColor(device, 64 - size / 2 + 1, 64 - size / 2 + 1);
+ IDirect3DSurface8 *readback;
+ D3DLOCKED_RECT locked_rect = get_rt(device, &readback);
+
+ color = get_rt_color(&locked_rect, 64 - size / 2 + 1, 64 - size / 2 + 1);
ok(color_match(color, 0x00ff0000, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
- color = getPixelColor(device, 64 + size / 2 - 1, 64 - size / 2 + 1);
+ color = get_rt_color(&locked_rect, 64 + size / 2 - 1, 64 - size / 2 + 1);
ok(color_match(color, 0x00ffff00, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
- color = getPixelColor(device, 64 - size / 2 + 1, 64 + size / 2 - 1);
+ color = get_rt_color(&locked_rect, 64 - size / 2 + 1, 64 + size / 2 - 1);
ok(color_match(color, 0x00000000, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
- color = getPixelColor(device, 64 + size / 2 - 1, 64 + size / 2 - 1);
+ color = get_rt_color(&locked_rect, 64 + size / 2 - 1, 64 + size / 2 - 1);
ok(color_match(color, 0x0000ff00, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
- color = getPixelColor(device, 64 - size / 2 - 1, 64 - size / 2 - 1);
- ok(color_match(color, 0x0000ffff, 0),
+ color = get_rt_color(&locked_rect, 64 - size / 2 - 1, 64 - size / 2 - 1);
+ ok(color_match(color, 0xff00ffff, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
- color = getPixelColor(device, 64 + size / 2 + 1, 64 - size / 2 - 1);
- ok(color_match(color, 0x0000ffff, 0),
+ color = get_rt_color(&locked_rect, 64 + size / 2 + 1, 64 - size / 2 - 1);
+ ok(color_match(color, 0xff00ffff, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
- color = getPixelColor(device, 64 - size / 2 - 1, 64 + size / 2 + 1);
- ok(color_match(color, 0x0000ffff, 0),
+ color = get_rt_color(&locked_rect, 64 - size / 2 - 1, 64 + size / 2 + 1);
+ ok(color_match(color, 0xff00ffff, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
- color = getPixelColor(device, 64 + size / 2 + 1, 64 + size / 2 + 1);
- ok(color_match(color, 0x0000ffff, 0),
+ color = get_rt_color(&locked_rect, 64 + size / 2 + 1, 64 + size / 2 + 1);
+ ok(color_match(color, 0xff00ffff, 0),
"Got unexpected color 0x%08x (case %u, %u, size %u).\n", color, i, j, size);
+
+ release_rt(readback);
}
}
IDirect3DDevice8_SetVertexShader(device, 0);
--
2.4.9
More information about the wine-patches
mailing list