From: Connor McAdams cmcadams@codeweavers.com
Signed-off-by: Connor McAdams cmcadams@codeweavers.com --- dlls/d3dx9_36/tests/surface.c | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 8b48d13d45b..70c4c993efa 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -279,6 +279,24 @@ static const BYTE dds_dxt5_8_8[] = 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x05,0x05,0x50,0x50, };
+/* + * 8x8 dxt5 image data, four 4x4 blocks: + * +-----+-----+ + * |Blue |Green| + * | | | + * +-----+-----+ + * |Red |Black| + * | | | + * +-----+-----+ + */ +static const BYTE dxt5_8_8[] = +{ + 0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x1f,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xf8,0x1f,0xf8,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x07,0xff,0x07,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0x1f,0x00,0x00,0x00,0x00,0x00, +}; + static HRESULT create_file(const char *filename, const unsigned char *data, const unsigned int size) { DWORD received; @@ -832,6 +850,35 @@ static inline void _check_pixel_4bpp(unsigned int line, const D3DLOCKED_RECT *lo ok_(__FILE__, line)(color == expected_color, "Got color 0x%08lx, expected 0x%08lx\n", color, expected_color); }
+#define check_dxt_pixel_4bpp(device, dxt_surf, width, height, x, y, color, todo) _check_dxt_pixel_4bpp(__LINE__, device,\ + dxt_surf, width, height, x, y, color, todo) +static inline void _check_dxt_pixel_4bpp(unsigned int line, IDirect3DDevice9 *device, IDirect3DSurface9 *dxt_surf, int width, + int height, int x, int y, DWORD expected_color, BOOL todo) +{ + IDirect3DSurface9 *decomp_surf; + D3DLOCKED_RECT lockrect; + DWORD color; + HRESULT hr; + RECT rect; + + hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &decomp_surf, NULL); + ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + hr = D3DXLoadSurfaceFromSurface(decomp_surf, NULL, NULL, dxt_surf, NULL, NULL, D3DX_FILTER_NONE, 0); + ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + SetRect(&rect, 0, 0, width, height); + hr = IDirect3DSurface9_LockRect(decomp_surf, &lockrect, &rect, D3DLOCK_READONLY); + ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + color = ((DWORD*)lockrect.pBits)[x + y * lockrect.Pitch / 4]; + todo_wine_if(todo) ok_(__FILE__, line)(color == expected_color, "Got color 0x%08lx, expected 0x%08lx\n", color, expected_color); + + hr = IDirect3DSurface9_UnlockRect(decomp_surf); + ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + check_release((IUnknown *)decomp_surf, 0); +} + static void test_D3DXLoadSurface(IDirect3DDevice9 *device) { HRESULT hr; @@ -1521,6 +1568,49 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
check_release((IUnknown *)newsurf, 1); check_release((IUnknown *)tex, 0); + + /* Misalignment tests but check the resulting image. */ + hr = IDirect3DDevice9_CreateTexture(device, 8, 8, 1, 0, D3DFMT_DXT5, D3DPOOL_SYSTEMMEM, &tex, NULL); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDirect3DTexture9_GetSurfaceLevel(tex, 0, &newsurf); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + SetRect(&rect, 0, 0, 8, 8); + hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, NULL, dxt5_8_8, + D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_NONE, 0); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 0, 0, 0xff0000ff, FALSE); /* Blue block, top left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 3, 3, 0xff0000ff, FALSE); /* Blue block, bottom right. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 7, 0, 0x00ff00ff, FALSE); /* Green block, top right. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 4, 3, 0x00ff00ff, FALSE); /* Green block, bottom left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 3, 4, 0x0000ffff, FALSE); /* Red block, top right. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 0, 7, 0x0000ffff, FALSE); /* Red block, bottom left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 4, 4, 0x000000ff, FALSE); /* Black block, top left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 7, 7, 0x000000ff, FALSE); /* Black block, bottom right. */ + + /* + * Load our surface into a destination rectangle that overlaps + * multiple blocks. Original data in the blocks should be + * preserved. + */ + SetRect(&rect, 4, 4, 8, 8); + SetRect(&destrect, 2, 2, 6, 6); + hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &destrect, dxt5_8_8, + D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_NONE, 0); + ok(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr); + + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 0, 0, 0xff0000ff, TRUE); /* Blue block, top left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 3, 3, 0x000000ff, TRUE); /* Blue block, bottom right. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 7, 0, 0x00ff00ff, TRUE); /* Green block, top right. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 4, 3, 0x000000ff, TRUE); /* Green block, bottom left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 3, 4, 0x000000ff, TRUE); /* Red block, top right. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 0, 7, 0x0000ffff, TRUE); /* Red block, bottom left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 4, 4, 0x000000ff, TRUE); /* Black block, top left. */ + check_dxt_pixel_4bpp(device, newsurf, 8, 8, 7, 7, 0x000000ff, TRUE); /* Black block, bottom right. */ + + check_release((IUnknown *)newsurf, 1); + check_release((IUnknown *)tex, 0); }
hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT1, D3DPOOL_SYSTEMMEM, &tex, NULL);