[PATCH 4/6] d3d11/tests: Introduce check_texture_color().

Józef Kucia jkucia at codeweavers.com
Mon Feb 29 11:35:50 CST 2016


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---
 dlls/d3d11/tests/d3d11.c | 84 +++++++++++++++++++++++-------------------------
 1 file changed, 41 insertions(+), 43 deletions(-)

diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 4054b2a..0d675f7 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -85,6 +85,7 @@ struct texture_readback
     ID3D11Resource *texture;
     D3D11_MAPPED_SUBRESOURCE map_desc;
     ID3D11DeviceContext *immediate_context;
+    unsigned int width, height;
 };
 
 static void get_texture_readback(ID3D11Texture2D *texture, struct texture_readback *rb)
@@ -109,6 +110,9 @@ static void get_texture_readback(ID3D11Texture2D *texture, struct texture_readba
         return;
     }
 
+    rb->width = texture_desc.Width;
+    rb->height = texture_desc.Height;
+
     ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
 
     ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->texture, (ID3D11Resource *)texture);
@@ -152,6 +156,35 @@ static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigne
     return color;
 }
 
+#define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
+static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
+        DWORD expected_color, BYTE max_diff)
+{
+    struct texture_readback rb;
+    unsigned int x = 0, y = 0;
+    BOOL all_match = TRUE;
+    DWORD color = 0;
+
+    get_texture_readback(texture, &rb);
+    for (y = 0; y < rb.height; ++y)
+    {
+        for (x = 0; x < rb.width; ++x)
+        {
+            color = get_readback_color(&rb, x, y);
+            if (!compare_color(color, expected_color, max_diff))
+            {
+                all_match = FALSE;
+                break;
+            }
+        }
+        if (!all_match)
+            break;
+    }
+    release_texture_readback(&rb);
+    ok_(__FILE__, line)(all_match,
+            "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
+}
+
 static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
 {
     ID3D11Device *device;
@@ -3580,7 +3613,6 @@ static void test_multiple_render_targets(void)
     D3D11_VIEWPORT vp;
     ID3D11Buffer *vb;
     ULONG refcount;
-    DWORD color;
     HRESULT hr;
 
     static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
@@ -3733,14 +3765,10 @@ static void test_multiple_render_targets(void)
 
     ID3D11DeviceContext_Draw(context, 4, 0);
 
-    color = get_texture_color(rt[0], 320, 240);
-    ok(compare_color(color, 0xffffffff, 2), "Got unexpected color 0x%08x.\n", color);
-    color = get_texture_color(rt[1], 320, 240);
-    ok(compare_color(color, 0x7f7f7f7f, 2), "Got unexpected color 0x%08x.\n", color);
-    color = get_texture_color(rt[2], 320, 240);
-    ok(compare_color(color, 0x33333333, 2), "Got unexpected color 0x%08x.\n", color);
-    color = get_texture_color(rt[3], 320, 240);
-    ok(compare_color(color, 0xff7f3300, 2), "Got unexpected color 0x%08x.\n", color);
+    check_texture_color(rt[0], 0xffffffff, 2);
+    check_texture_color(rt[1], 0x7f7f7f7f, 2);
+    check_texture_color(rt[2], 0x33333333, 2);
+    check_texture_color(rt[3], 0xff7f3300, 2);
 
     ID3D11Buffer_Release(vb);
     ID3D11PixelShader_Release(ps);
@@ -3917,8 +3945,7 @@ static void test_scissor(void)
     ID3D11DeviceContext_OMSetRenderTargets(immediate_context, 1, &rtv, NULL);
 
     ID3D11DeviceContext_ClearRenderTargetView(immediate_context, rtv, red);
-    color = get_texture_color(backbuffer, 320, 240);
-    ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
+    check_texture_color(backbuffer, 0xff0000ff, 1);
 
     ID3D11DeviceContext_Draw(immediate_context, 4, 0);
     color = get_texture_color(backbuffer, 320, 60);
@@ -4617,19 +4644,10 @@ static void test_update_subresource(void)
     ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
 
     ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
+    check_texture_color(backbuffer, 0x7f0000ff, 1);
 
     ID3D11DeviceContext_Draw(context, 4, 0);
-    get_texture_readback(backbuffer, &rb);
-    for (i = 0; i < 4; ++i)
-    {
-        for (j = 0; j < 4; ++j)
-        {
-            color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120);
-            ok(compare_color(color, 0x00000000, 0),
-                    "Got unexpected color 0x%08x at (%u, %u).\n", color, j, i);
-        }
-    }
-    release_texture_readback(&rb);
+    check_texture_color(backbuffer, 0x00000000, 0);
 
     set_box(&box, 1, 1, 0, 3, 3, 1);
     ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
@@ -5113,11 +5131,7 @@ static void test_multisample_init(void)
     ID3D11Device *device;
     ID3D11DeviceContext *context;
     ULONG refcount;
-    DWORD color;
     HRESULT hr;
-    unsigned int x, y;
-    struct texture_readback rb;
-    BOOL all_zero = TRUE;
     UINT count = 0;
     HWND window;
     IDXGISwapChain *swapchain;
@@ -5166,23 +5180,7 @@ static void test_multisample_init(void)
     ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)backbuffer, 0,
             (ID3D11Resource *)multi, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
 
-    get_texture_readback(backbuffer, &rb);
-    for (y = 0; y < 480; ++y)
-    {
-        for (x = 0; x < 640; ++x)
-        {
-            color = get_readback_color(&rb, x, y);
-            if (!compare_color(color, 0x00000000, 0))
-            {
-                all_zero = FALSE;
-                break;
-            }
-        }
-        if (!all_zero)
-            break;
-    }
-    release_texture_readback(&rb);
-    todo_wine ok(all_zero, "Got unexpected color 0x%08x, position %ux%u.\n", color, x, y);
+    todo_wine check_texture_color(backbuffer, 0x00000000, 0);
 
     ID3D11DeviceContext_Release(context);
     ID3D11RenderTargetView_Release(rtview);
-- 
2.4.10




More information about the wine-patches mailing list