[PATCH 3/4] ddraw/tests: Add pitch alignment tests (try 3)

Stefan Dösinger stefan at codeweavers.com
Tue Feb 28 05:19:27 CST 2012


This patch is a side product of my attempts to debug bug 21238. It
confirms that the 8 byte aligned pitches are correct for all pools.

try 2: Don't fail and crash if video memory surfaces are not available
try 3: 64 bit ddraw has 4 byte alignment for systemmem and managed surfaces
---
 dlls/ddraw/tests/ddraw1.c |   79 +++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw2.c |   83 +++++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw4.c |   84 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/ddraw/tests/ddraw7.c |   85 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 331 insertions(+), 0 deletions(-)

diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 3d173d9..7266a99 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -1121,6 +1121,84 @@ static void test_zenable(void)
     DestroyWindow(window);
 }
 
+static void test_pitch_alignment(void)
+{
+    IDirectDraw *ddraw;
+    IDirectDrawSurface *surface;
+    HRESULT hr;
+    static const struct
+    {
+        DWORD caps;
+        UINT align;
+        LONG pitch, broken_pitch;
+        const char *name;
+    }
+    pools[] =
+    {
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
+            8, 0, 0, "D3DPOOL_DEFAULT"
+        },
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
+            8, 16, 12, "D3DPOOL_SYSTEMMEM"
+        },
+    };
+    unsigned int i;
+    DDSURFACEDESC ddsd;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    hr = IDirectDraw_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+    for (i = 0; i < (sizeof(pools) / sizeof(*pools)); i++)
+    {
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+        ddsd.dwWidth = 5;
+        ddsd.dwHeight = 5;
+        ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
+        ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
+        U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
+        U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xF800;
+        U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07E0;
+        U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001F;
+        ddsd.ddsCaps.dwCaps = pools[i].caps;
+
+        hr = IDirectDraw_CreateSurface(ddraw, &ddsd, &surface, NULL);
+        ok(SUCCEEDED(hr) || hr == DDERR_UNSUPPORTEDFORMAT || hr == DDERR_NODIRECTDRAWHW,
+                "%s: Failed to create surface, hr %#x.\n", pools[i].name, hr);
+        if (!surface)
+        {
+            skip("%s: Failed to create surface, skipping pitch alignment test.\n", pools[i].name);
+            continue;
+        }
+
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        hr = IDirectDrawSurface_GetSurfaceDesc(surface, &ddsd);
+        ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
+
+        /* 64 bit ddraw.dll has 4 byte alignment for SYSTEMMEM and MANAGED surfaces. We do not
+         * care about this because all ddraw games are 32 bit */
+        ok(!(ddsd.lPitch & (pools[i].align - 1)) || broken(!(ddsd.lPitch & 3)),
+                "%s: Pitch %d is not %u byte aligned.\n", pools[i].name, ddsd.lPitch, pools[i].align);
+        if (pools[i].pitch)
+            ok(ddsd.lPitch == pools[i].pitch || broken(ddsd.lPitch == pools[i].broken_pitch),
+                    "%s: Expected pitch %d, got %d.\n", pools[i].name, pools[i].pitch, ddsd.lPitch);
+
+        IDirectDrawSurface_Release(surface);
+    }
+
+    IDirectDraw_Release(ddraw);
+}
+
 START_TEST(ddraw1)
 {
     test_coop_level_create_device_window();
@@ -1130,4 +1208,5 @@ START_TEST(ddraw1)
     test_coop_level_threaded();
     test_viewport_interfaces();
     test_zenable();
+    test_pitch_alignment();
 }
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index ba8d3b6..7cd985a 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -1383,6 +1383,88 @@ static void test_zenable(void)
     DestroyWindow(window);
 }
 
+static void test_pitch_alignment(void)
+{
+    IDirectDraw2 *ddraw;
+    IDirectDrawSurface *surface1;
+    IDirectDrawSurface2 *surface;
+    HRESULT hr;
+    static const struct
+    {
+        DWORD caps;
+        UINT align;
+        LONG pitch, broken_pitch;
+        const char *name;
+    }
+    pools[] =
+    {
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY,
+            8, 0, 0, "D3DPOOL_DEFAULT"
+        },
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY,
+            8, 16, 12, "D3DPOOL_SYSTEMMEM"
+        },
+    };
+    unsigned int i;
+    DDSURFACEDESC ddsd;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    hr = IDirectDraw2_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+    for (i = 0; i < (sizeof(pools) / sizeof(*pools)); i++)
+    {
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+        ddsd.dwWidth = 5;
+        ddsd.dwHeight = 5;
+        ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
+        ddsd.ddpfPixelFormat.dwFlags = DDPF_RGB;
+        U1(ddsd.ddpfPixelFormat).dwRGBBitCount = 16;
+        U2(ddsd.ddpfPixelFormat).dwRBitMask = 0xF800;
+        U3(ddsd.ddpfPixelFormat).dwGBitMask = 0x07E0;
+        U4(ddsd.ddpfPixelFormat).dwBBitMask = 0x001F;
+        ddsd.ddsCaps.dwCaps = pools[i].caps;
+
+        hr = IDirectDraw2_CreateSurface(ddraw, &ddsd, &surface1, NULL);
+        ok(SUCCEEDED(hr) || hr == DDERR_UNSUPPORTEDFORMAT || hr == DDERR_NODIRECTDRAWHW,
+                "%s: Failed to create surface, hr %#x.\n", pools[i].name, hr);
+        if (!surface1)
+        {
+            skip("%s: Failed to create surface, skipping pitch alignment test.\n", pools[i].name);
+            continue;
+        }
+        hr = IDirectDrawSurface_QueryInterface(surface1, &IID_IDirectDrawSurface2, (void **)&surface);
+        ok(SUCCEEDED(hr), "%s: Failed to get DirectDrawSurace2 interface, hr %#x.\n", pools[i].name, hr);
+        IDirectDrawSurface_Release(surface1);
+
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        hr = IDirectDrawSurface2_GetSurfaceDesc(surface, &ddsd);
+        ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
+
+        /* 64 bit ddraw.dll has 4 byte alignment for SYSTEMMEM and MANAGED surfaces. We do not
+         * care about this because all ddraw games are 32 bit */
+        ok(!(ddsd.lPitch & (pools[i].align - 1)) || broken(!(ddsd.lPitch & 3)),
+                "%s: Pitch %d is not %u byte aligned.\n", pools[i].name, ddsd.lPitch, pools[i].align);
+        if (pools[i].pitch)
+            ok(ddsd.lPitch == pools[i].pitch || broken(ddsd.lPitch == pools[i].broken_pitch),
+                    "%s: Expected pitch %d, got %d.\n", pools[i].name, pools[i].pitch, ddsd.lPitch);
+
+        IDirectDrawSurface2_Release(surface);
+    }
+
+    IDirectDraw2_Release(ddraw);
+}
+
 START_TEST(ddraw2)
 {
     test_coop_level_create_device_window();
@@ -1394,4 +1476,5 @@ START_TEST(ddraw2)
     test_texture_load_ckey();
     test_viewport_interfaces();
     test_zenable();
+    test_pitch_alignment();
 }
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index d9ed90d..0c62d66 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -1490,6 +1490,89 @@ static void test_zenable(void)
     DestroyWindow(window);
 }
 
+static void test_pitch_alignment(void)
+{
+    IDirectDraw4 *ddraw;
+    IDirectDrawSurface4 *surface;
+    HRESULT hr;
+    static const struct
+    {
+        DWORD caps, caps2;
+        UINT align;
+        LONG pitch, broken_pitch;
+        const char *name;
+    }
+    pools[] =
+    {
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
+            8, 0, 0, "D3DPOOL_DEFAULT"
+        },
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
+            8, 16, 12, "D3DPOOL_SYSTEMMEM"
+        },
+        {
+            DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
+            8, 16, 12, "D3DPOOL_MANAGED"
+        }
+    };
+    unsigned int i;
+    DDSURFACEDESC2 ddsd;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    hr = IDirectDraw4_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+    for (i = 0; i < (sizeof(pools) / sizeof(*pools)); i++)
+    {
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+        ddsd.dwWidth = 5;
+        ddsd.dwHeight = 5;
+        U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
+        U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
+        U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
+        U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
+        U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
+        U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
+        ddsd.ddsCaps.dwCaps = pools[i].caps;
+        ddsd.ddsCaps.dwCaps2 = pools[i].caps2;
+
+        hr = IDirectDraw4_CreateSurface(ddraw, &ddsd, &surface, NULL);
+        ok(SUCCEEDED(hr) || hr == DDERR_UNSUPPORTEDFORMAT || hr == DDERR_NODIRECTDRAWHW,
+                "%s: Failed to create surface, hr %#x.\n", pools[i].name, hr);
+        if (!surface)
+        {
+            skip("%s: Failed to create surface, skipping pitch alignment test.\n", pools[i].name);
+            continue;
+        }
+
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        hr = IDirectDrawSurface4_GetSurfaceDesc(surface, &ddsd);
+        ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
+
+        /* 64 bit ddraw.dll has 4 byte alignment for SYSTEMMEM and MANAGED surfaces. We do not
+         * care about this because all ddraw games are 32 bit */
+        ok(!(ddsd.lPitch & (pools[i].align - 1)) || broken(!(ddsd.lPitch & 3)),
+                "%s: Pitch %d is not %u byte aligned.\n", pools[i].name, ddsd.lPitch, pools[i].align);
+        if (pools[i].pitch)
+            ok(ddsd.lPitch == pools[i].pitch || broken(ddsd.lPitch == pools[i].broken_pitch),
+                    "%s: Expected pitch %d, got %d.\n", pools[i].name, pools[i].pitch, ddsd.lPitch);
+
+        IDirectDrawSurface4_Release(surface);
+    }
+
+    IDirectDraw4_Release(ddraw);
+}
+
 START_TEST(ddraw4)
 {
     test_process_vertices();
@@ -1502,4 +1585,5 @@ START_TEST(ddraw4)
     test_texture_load_ckey();
     test_viewport_interfaces();
     test_zenable();
+    test_pitch_alignment();
 }
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 2ea77fe..ce93847 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -1277,6 +1277,90 @@ static void test_zenable(void)
     DestroyWindow(window);
 }
 
+static void test_pitch_alignment(void)
+{
+    IDirectDraw7 *ddraw;
+    IDirectDrawSurface7 *surface;
+    HRESULT hr;
+    static const struct
+    {
+        DWORD caps, caps2;
+        UINT align;
+        LONG pitch, broken_pitch;
+        const char *name;
+    }
+    pools[] =
+    {
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY, 0,
+            8, 0, 0, "D3DPOOL_DEFAULT"
+        },
+        {
+            DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY, 0,
+            8, 16, 12, "D3DPOOL_SYSTEMMEM"
+        },
+        {
+            DDSCAPS_TEXTURE, DDSCAPS2_TEXTUREMANAGE,
+            8, 16, 12, "D3DPOOL_MANAGED"
+        }
+    };
+    unsigned int i;
+    DDSURFACEDESC2 ddsd;
+
+    if (!(ddraw = create_ddraw()))
+    {
+        skip("Failed to create a ddraw object, skipping test.\n");
+        return;
+    }
+
+    hr = IDirectDraw7_SetCooperativeLevel(ddraw, NULL, DDSCL_NORMAL);
+    ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+
+    for (i = 0; i < (sizeof(pools) / sizeof(*pools)); i++)
+    {
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT;
+        ddsd.dwWidth = 5;
+        ddsd.dwHeight = 5;
+        U4(ddsd).ddpfPixelFormat.dwSize = sizeof(U4(ddsd).ddpfPixelFormat);
+        U4(ddsd).ddpfPixelFormat.dwFlags = DDPF_RGB;
+        U1(U4(ddsd).ddpfPixelFormat).dwRGBBitCount = 16;
+        U2(U4(ddsd).ddpfPixelFormat).dwRBitMask = 0xF800;
+        U3(U4(ddsd).ddpfPixelFormat).dwGBitMask = 0x07E0;
+        U4(U4(ddsd).ddpfPixelFormat).dwBBitMask = 0x001F;
+        ddsd.ddsCaps.dwCaps = pools[i].caps;
+        ddsd.ddsCaps.dwCaps2 = pools[i].caps2;
+
+        /* 64 bit ddraw.dll rejects the creation on TEXTUREMANAGE surfaces in ddraw7, but not in ddraw4 */
+        hr = IDirectDraw7_CreateSurface(ddraw, &ddsd, &surface, NULL);
+        ok(SUCCEEDED(hr) || hr == DDERR_UNSUPPORTEDFORMAT || hr == DDERR_NODIRECTDRAWHW || broken(hr == E_NOINTERFACE),
+                "%s: Failed to create surface, hr %#x. notimpl is %x\n", pools[i].name, hr, E_NOTIMPL);
+        if (!surface)
+        {
+            skip("%s: Failed to create surface, skipping pitch alignment test.\n", pools[i].name);
+            continue;
+        }
+
+        memset(&ddsd, 0, sizeof(ddsd));
+        ddsd.dwSize = sizeof(ddsd);
+        hr = IDirectDrawSurface7_GetSurfaceDesc(surface, &ddsd);
+        ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr);
+
+        /* 64 bit ddraw.dll has 4 byte alignment for SYSTEMMEM and MANAGED surfaces. We do not
+         * care about this because all ddraw games are 32 bit */
+        ok(!(ddsd.lPitch & (pools[i].align - 1)) || broken(!(ddsd.lPitch & 3)),
+                "%s: Pitch %d is not %u byte aligned.\n", pools[i].name, ddsd.lPitch, pools[i].align);
+        if (pools[i].pitch)
+            ok(ddsd.lPitch == pools[i].pitch || broken(ddsd.lPitch == pools[i].broken_pitch),
+                    "%s: Expected pitch %d, got %d.\n", pools[i].name, pools[i].pitch, ddsd.lPitch);
+
+        IDirectDrawSurface7_Release(surface);
+    }
+
+    IDirectDraw7_Release(ddraw);
+}
+
 START_TEST(ddraw7)
 {
     HMODULE module = GetModuleHandleA("ddraw.dll");
@@ -1296,4 +1380,5 @@ START_TEST(ddraw7)
     test_depth_blit();
     test_texture_load_ckey();
     test_zenable();
+    test_pitch_alignment();
 }
-- 
1.7.3.4




More information about the wine-patches mailing list