Signed-off-by: Matteo Bruni mbruni@codeweavers.com --- Tests show that source rectangle misalignment never causes the function to fail. Just take the resample path in those cases.
Also reorganize the code a bit.
dlls/d3dx9_36/surface.c | 36 +++++++++++++++-------------------- dlls/d3dx9_36/tests/surface.c | 2 +- dlls/d3dx9_36/tests/texture.c | 34 ++++++++++++++++----------------- 3 files changed, 32 insertions(+), 40 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c index a2eca9cbdbd..e85805df8ec 100644 --- a/dlls/d3dx9_36/surface.c +++ b/dlls/d3dx9_36/surface.c @@ -1848,10 +1848,10 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, DWORD filter, D3DCOLOR color_key) { const struct pixel_format_desc *srcformatdesc, *destformatdesc; + struct volume src_size, dst_size; IDirect3DSurface9 *surface; D3DSURFACE_DESC surfdesc; D3DLOCKED_RECT lockrect; - struct volume src_size, dst_size; HRESULT hr;
TRACE("(%p, %p, %s, %p, %#x, %u, %p, %s, %#x, 0x%08x)\n", @@ -1871,14 +1871,18 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, return E_FAIL; }
- if (filter == D3DX_DEFAULT) - filter = D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER; - - IDirect3DSurface9_GetDesc(dst_surface, &surfdesc); + srcformatdesc = get_format_info(src_format); + if (srcformatdesc->type == FORMAT_UNKNOWN) + { + FIXME("Unsupported format %#x.\n", src_format); + return E_NOTIMPL; + }
src_size.width = src_rect->right - src_rect->left; src_size.height = src_rect->bottom - src_rect->top; src_size.depth = 1; + + IDirect3DSurface9_GetDesc(dst_surface, &surfdesc); if (!dst_rect) { dst_size.width = surfdesc.Width; @@ -1899,14 +1903,10 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, return D3D_OK; } dst_size.depth = 1; - - srcformatdesc = get_format_info(src_format); destformatdesc = get_format_info(surfdesc.Format); - if (srcformatdesc->type == FORMAT_UNKNOWN) - { - FIXME("Unsupported format %#x.\n", src_format); - return E_NOTIMPL; - } + + if (filter == D3DX_DEFAULT) + filter = D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER;
if (FAILED(hr = lock_surface(dst_surface, dst_rect, &lockrect, &surface, TRUE))) return hr; @@ -1914,16 +1914,10 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface, if (src_format == surfdesc.Format && dst_size.width == src_size.width && dst_size.height == src_size.height - && color_key == 0) /* Simple copy. */ + && color_key == 0 + && !(src_rect->left & (srcformatdesc->block_width - 1)) + && !(src_rect->top & (srcformatdesc->block_height - 1))) /* Simple copy. */ { - if (src_rect->left & (srcformatdesc->block_width - 1) - || src_rect->top & (srcformatdesc->block_height - 1)) - { - WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect)); - unlock_surface(dst_surface, dst_rect, surface, FALSE); - return D3DXERR_INVALIDDATA; - } - copy_pixels(src_memory, src_pitch, 0, lockrect.pBits, lockrect.Pitch, 0, &src_size, srcformatdesc); } diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c index 04ce57fa4f5..ba441879597 100644 --- a/dlls/d3dx9_36/tests/surface.c +++ b/dlls/d3dx9_36/tests/surface.c @@ -1351,7 +1351,7 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
hr = D3DXLoadSurfaceFromMemory(newsurf, NULL, &rect, &dds_dxt5_8_8[128], D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_POINT, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
check_release((IUnknown *)newsurf, 1); check_release((IUnknown *)tex, 0); diff --git a/dlls/d3dx9_36/tests/texture.c b/dlls/d3dx9_36/tests/texture.c index fc1589d25e3..49aed94a174 100644 --- a/dlls/d3dx9_36/tests/texture.c +++ b/dlls/d3dx9_36/tests/texture.c @@ -1804,28 +1804,26 @@ static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
hr = D3DXLoadSurfaceFromMemory(surface, NULL, &rect, &dds_dxt5_8_8[128], D3DFMT_DXT5, 16 * 2, NULL, &rect, D3DX_FILTER_POINT, 0); - todo_wine ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - if (SUCCEEDED(hr)) - { - hr = D3DXLoadSurfaceFromSurface(uncompressed_surface, NULL, NULL, surface, NULL, NULL, D3DX_FILTER_NONE, 0); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + hr = D3DXLoadSurfaceFromSurface(uncompressed_surface, NULL, NULL, surface, NULL, NULL, D3DX_FILTER_NONE, 0); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
- hr = IDirect3DSurface9_LockRect(uncompressed_surface, &lock_rect, NULL, D3DLOCK_READONLY); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - for (y = 0; y < 8; ++y) + hr = IDirect3DSurface9_LockRect(uncompressed_surface, &lock_rect, NULL, D3DLOCK_READONLY); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + for (y = 0; y < 8; ++y) + { + for (x = 0; x < 8; ++x) { - for (x = 0; x < 8; ++x) - { - ok(compare_color(((DWORD *)lock_rect.pBits)[lock_rect.Pitch / 4 * y + x], - dds_dxt5_8_8_expected_misaligned_3[y * 8 + x], 0), - "Color at position %u, %u is 0x%08x, expected 0x%08x.\n", - x, y, ((DWORD *)lock_rect.pBits)[lock_rect.Pitch / 4 * y + x], - dds_dxt5_8_8_expected_misaligned_3[y * 8 + x]); - } + todo_wine_if (x >= 2 && x < 6 && y >= 2 && y < 6) + ok(compare_color(((DWORD *)lock_rect.pBits)[lock_rect.Pitch / 4 * y + x], + dds_dxt5_8_8_expected_misaligned_3[y * 8 + x], 0), + "Color at position %u, %u is 0x%08x, expected 0x%08x.\n", + x, y, ((DWORD *)lock_rect.pBits)[lock_rect.Pitch / 4 * y + x], + dds_dxt5_8_8_expected_misaligned_3[y * 8 + x]); } - hr = IDirect3DSurface9_UnlockRect(uncompressed_surface); - ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); } + hr = IDirect3DSurface9_UnlockRect(uncompressed_surface); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
IDirect3DSurface9_Release(uncompressed_surface); IDirect3DSurface9_Release(surface);