d3dx9: Pass rectangle to {lock|unlock}_surface().

This fixes regressions introduced by commits
65956ae50a, 092c14b9d8.
Surface source or destination rectangles were left behind.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47546
Signed-off-by: Paul Gofman <gofmanp@gmail.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2019-08-05 12:36:27 +03:00 committed by Alexandre Julliard
parent 2859c22cc6
commit 378204527e
4 changed files with 153 additions and 87 deletions

View File

@ -121,9 +121,9 @@ HRESULT load_volume_from_dds(IDirect3DVolume9 *dst_volume, const PALETTEENTRY *d
const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
HRESULT load_volume_texture_from_dds(IDirect3DVolumeTexture9 *volume_texture, const void *src_data,
const PALETTEENTRY *palette, DWORD filter, DWORD color_key, const D3DXIMAGE_INFO *src_info) DECLSPEC_HIDDEN;
HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
HRESULT lock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock,
IDirect3DSurface9 **temp_surface, BOOL write) DECLSPEC_HIDDEN;
HRESULT unlock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock,
IDirect3DSurface9 *temp_surface, BOOL update) DECLSPEC_HIDDEN;
unsigned short float_32_to_16(const float in) DECLSPEC_HIDDEN;

View File

@ -198,9 +198,10 @@ static const struct {
{ 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000, D3DFMT_X8B8G8R8 },
};
HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
HRESULT lock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock,
IDirect3DSurface9 **temp_surface, BOOL write)
{
unsigned int width, height;
IDirect3DDevice9 *device;
D3DSURFACE_DESC desc;
DWORD lock_flag;
@ -208,25 +209,36 @@ HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
lock_flag = write ? D3DLOCK_DISCARD : D3DLOCK_READONLY;
*temp_surface = NULL;
if (FAILED(hr = IDirect3DSurface9_LockRect(surface, lock, NULL, lock_flag)))
if (FAILED(hr = IDirect3DSurface9_LockRect(surface, lock, surface_rect, lock_flag)))
{
IDirect3DSurface9_GetDevice(surface, &device);
IDirect3DSurface9_GetDesc(surface, &desc);
hr = write ? IDirect3DDevice9_CreateOffscreenPlainSurface(device, desc.Width, desc.Height,
if (surface_rect)
{
width = surface_rect->right - surface_rect->left;
height = surface_rect->bottom - surface_rect->top;
}
else
{
width = desc.Width;
height = desc.Height;
}
hr = write ? IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height,
desc.Format, D3DPOOL_SYSTEMMEM, temp_surface, NULL)
: IDirect3DDevice9_CreateRenderTarget(device, desc.Width, desc.Height,
: IDirect3DDevice9_CreateRenderTarget(device, width, height,
desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, temp_surface, NULL);
if (FAILED(hr))
{
WARN("Failed to create temporary surface, surface %p, format %#x,"
" usage %#x, pool %#x, write %#x, width %u, height %u.\n",
surface, desc.Format, desc.Usage, desc.Pool, write, desc.Width, desc.Height);
surface, desc.Format, desc.Usage, desc.Pool, write, width, height);
IDirect3DDevice9_Release(device);
return hr;
}
if (write || SUCCEEDED(hr = IDirect3DDevice9_StretchRect(device, surface, NULL,
if (write || SUCCEEDED(hr = IDirect3DDevice9_StretchRect(device, surface, surface_rect,
*temp_surface, NULL, D3DTEXF_NONE)))
hr = IDirect3DSurface9_LockRect(*temp_surface, lock, NULL, lock_flag);
@ -244,20 +256,34 @@ HRESULT lock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
return hr;
}
HRESULT unlock_surface(IDirect3DSurface9 *surface, D3DLOCKED_RECT *lock,
HRESULT unlock_surface(IDirect3DSurface9 *surface, const RECT *surface_rect, D3DLOCKED_RECT *lock,
IDirect3DSurface9 *temp_surface, BOOL update)
{
IDirect3DDevice9 *device;
POINT surface_point;
HRESULT hr;
if (!temp_surface)
return IDirect3DSurface9_UnlockRect(surface);
{
hr = IDirect3DSurface9_UnlockRect(surface);
return hr;
}
hr = IDirect3DSurface9_UnlockRect(temp_surface);
if (update)
{
if (surface_rect)
{
surface_point.x = surface_rect->left;
surface_point.y = surface_rect->top;
}
else
{
surface_point.x = 0;
surface_point.y = 0;
}
IDirect3DSurface9_GetDevice(surface, &device);
if (FAILED(hr = IDirect3DDevice9_UpdateSurface(device, temp_surface, NULL, surface, NULL)))
if (FAILED(hr = IDirect3DDevice9_UpdateSurface(device, temp_surface, NULL, surface, &surface_point)))
WARN("Updating surface failed, hr %#x, surface %p, temp_surface %p.\n",
hr, surface, temp_surface);
IDirect3DDevice9_Release(device);
@ -569,7 +595,7 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSur
return hr;
}
hr = lock_surface(src_surface, &locked_rect, &temp_surface, FALSE);
hr = lock_surface(src_surface, NULL, &locked_rect, &temp_surface, FALSE);
if (FAILED(hr))
{
ID3DXBuffer_Release(buffer);
@ -582,7 +608,7 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSur
copy_pixels(locked_rect.pBits, locked_rect.Pitch, 0, pixels, dst_pitch, 0,
&volume, pixel_format);
unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
unlock_surface(src_surface, NULL, &locked_rect, temp_surface, FALSE);
*dst_buffer = buffer;
return D3D_OK;
@ -1870,7 +1896,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
return E_NOTIMPL;
}
if (FAILED(hr = lock_surface(dst_surface, &lockrect, &surface, TRUE)))
if (FAILED(hr = lock_surface(dst_surface, dst_rect, &lockrect, &surface, TRUE)))
return hr;
if (src_format == surfdesc.Format
@ -1886,7 +1912,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
&& src_size.height != surfdesc.Height))
{
WARN("Source rect %s is misaligned.\n", wine_dbgstr_rect(src_rect));
unlock_surface(dst_surface, &lockrect, surface, FALSE);
unlock_surface(dst_surface, dst_rect, &lockrect, surface, FALSE);
return D3DXERR_INVALIDDATA;
}
@ -1899,7 +1925,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
|| !is_conversion_to_supported(destformatdesc))
{
FIXME("Unsupported format conversion %#x -> %#x.\n", src_format, surfdesc.Format);
unlock_surface(dst_surface, &lockrect, surface, FALSE);
unlock_surface(dst_surface, dst_rect, &lockrect, surface, FALSE);
return E_NOTIMPL;
}
@ -1920,7 +1946,7 @@ HRESULT WINAPI D3DXLoadSurfaceFromMemory(IDirect3DSurface9 *dst_surface,
}
}
return unlock_surface(dst_surface, &lockrect, surface, TRUE);
return unlock_surface(dst_surface, dst_rect, &lockrect, surface, TRUE);
}
/************************************************************
@ -2004,13 +2030,13 @@ HRESULT WINAPI D3DXLoadSurfaceFromSurface(IDirect3DSurface9 *dst_surface,
src_rect = &s;
}
if (FAILED(lock_surface(src_surface, &lock, &temp_surface, FALSE)))
if (FAILED(lock_surface(src_surface, NULL, &lock, &temp_surface, FALSE)))
return D3DXERR_INVALIDDATA;
hr = D3DXLoadSurfaceFromMemory(dst_surface, dst_palette, dst_rect, lock.pBits,
src_desc.Format, lock.Pitch, src_palette, src_rect, filter, color_key);
if (FAILED(unlock_surface(src_surface, &lock, temp_surface, FALSE)))
if (FAILED(unlock_surface(src_surface, NULL, &lock, temp_surface, FALSE)))
return D3DXERR_INVALIDDATA;
return hr;
@ -2186,12 +2212,12 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
TRACE("Using pixel format %s %#x\n", debugstr_guid(&wic_pixel_format), d3d_pixel_format);
if (src_surface_desc.Format == d3d_pixel_format) /* Simple copy */
{
if (FAILED(hr = lock_surface(src_surface, &locked_rect, &temp_surface, FALSE)))
if (FAILED(hr = lock_surface(src_surface, src_rect, &locked_rect, &temp_surface, FALSE)))
goto cleanup;
IWICBitmapFrameEncode_WritePixels(frame, height,
locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits);
unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
unlock_surface(src_surface, src_rect, &locked_rect, temp_surface, FALSE);
}
else /* Pixel format conversion */
{
@ -2221,14 +2247,14 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
hr = E_OUTOFMEMORY;
goto cleanup;
}
if (FAILED(hr = lock_surface(src_surface, &locked_rect, &temp_surface, FALSE)))
if (FAILED(hr = lock_surface(src_surface, src_rect, &locked_rect, &temp_surface, FALSE)))
{
HeapFree(GetProcessHeap(), 0, dst_data);
goto cleanup;
}
convert_argb_pixels(locked_rect.pBits, locked_rect.Pitch, 0, &size, src_format_desc,
dst_data, dst_pitch, 0, &size, dst_format_desc, 0, NULL);
unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
unlock_surface(src_surface, src_rect, &locked_rect, temp_surface, FALSE);
IWICBitmapFrameEncode_WritePixels(frame, height, dst_pitch, dst_pitch * height, dst_data);
HeapFree(GetProcessHeap(), 0, dst_data);

View File

@ -957,17 +957,34 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
check_pixel_4bpp(&lockrect, 1, 1, 0xfffe9aff);
IDirect3DSurface9_UnlockRect(surf);
hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8,
8, NULL, &rect, D3DX_FILTER_NONE, 0);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
check_pixel_4bpp(&lockrect, 1, 1, 0x8df62bc3);
IDirect3DSurface9_UnlockRect(surf);
hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10, 8, NULL, &rect, D3DX_FILTER_NONE, 0);
ok(hr == D3D_OK, "D3DXLoadSurfaceFromMemory returned %#x, expected %#x\n", hr, D3D_OK);
SetRect(&rect, 0, 0, 1, 1);
SetRect(&destrect, 1, 1, 2, 2);
hr = D3DXLoadSurfaceFromMemory(surf, NULL, &destrect, pixdata_a8b8g8r8, D3DFMT_A8B8G8R8,
8, NULL, &rect, D3DX_FILTER_NONE, 0);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
check_pixel_4bpp(&lockrect, 0, 0, 0xc3f04c39);
check_pixel_4bpp(&lockrect, 1, 0, 0x2392e85a);
check_pixel_4bpp(&lockrect, 0, 1, 0x09fd97b1);
check_pixel_4bpp(&lockrect, 1, 1, 0xc3f04c39);
IDirect3DSurface9_UnlockRect(surf);
SetRect(&rect, 0, 0, 2, 2);
hr = D3DXLoadSurfaceFromMemory(surf, NULL, NULL, pixdata_a2r10g10b10, D3DFMT_A2R10G10B10,
8, NULL, &rect, D3DX_FILTER_NONE, 0);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
IDirect3DSurface9_LockRect(surf, &lockrect, NULL, D3DLOCK_READONLY);
check_pixel_4bpp(&lockrect, 0, 0, 0x555c95bf);
check_pixel_4bpp(&lockrect, 1, 0, 0x556d663f);
@ -1386,98 +1403,121 @@ static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
{
HRESULT hr;
IDirect3DSurface9 *surface;
RECT rect;
D3DLOCKED_RECT lock_rect;
D3DXIMAGE_INFO image_info;
const BYTE pixels[] = { 0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff };
const BYTE pixels[] =
{0xff, 0x00, 0x00, 0x00, 0xff, 0x00,
0x00, 0x00, 0xff, 0x00, 0x00, 0xff,};
DWORD pitch = sizeof(pixels) / 2;
IDirect3DSurface9 *surface;
D3DXIMAGE_INFO image_info;
D3DLOCKED_RECT lock_rect;
HRESULT hr;
RECT rect;
hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2, 2, D3DFMT_R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
if (FAILED(hr)) {
skip("Couldn't create surface\n");
if (FAILED(hr))
{
skip("Couldn't create surface.\n");
return;
}
SetRect(&rect, 0, 0, 2, 2);
hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8, pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
if (SUCCEEDED(hr)) {
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8,
pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp", NULL, D3DX_FILTER_NONE, 0, &image_info);
ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
if (FAILED(hr)) goto next_tests;
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, NULL);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
ok(image_info.Height == 2, "Wrong height %u\n", image_info.Height);
ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u\n", image_info.ImageFileFormat);
hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.bmp",
NULL, D3DX_FILTER_NONE, 0, &image_info);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
if (FAILED(hr)) goto next_tests;
ok(image_info.Width == 2, "Wrong width %u.\n", image_info.Width);
ok(image_info.Height == 2, "Wrong height %u.\n", image_info.Height);
ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x.\n", image_info.Format);
ok(image_info.ImageFileFormat == D3DXIFF_BMP, "Wrong file format %u.\n", image_info.ImageFileFormat);
ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
IDirect3DSurface9_UnlockRect(surface);
} else skip("Couldn't fill surface\n");
ok(!memcmp(lock_rect.pBits, pixels, pitch),
"Pixel data mismatch in the first row.\n");
ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
"Pixel data mismatch in the second row.\n");
IDirect3DSurface9_UnlockRect(surface);
SetRect(&rect, 0, 1, 2, 2);
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
SetRect(&rect, 0, 0, 2, 1);
hr = D3DXLoadSurfaceFromFileA(surface, NULL, &rect, "saved_surface.bmp", NULL,
D3DX_FILTER_NONE, 0, &image_info);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(!memcmp(lock_rect.pBits, pixels + pitch, pitch),
"Pixel data mismatch in the first row.\n");
ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
"Pixel data mismatch in the second row.\n");
IDirect3DSurface9_UnlockRect(surface);
SetRect(&rect, 0, 0, 2, 2);
hr = D3DXLoadSurfaceFromMemory(surface, NULL, NULL, pixels, D3DFMT_R8G8B8,
pitch, NULL, &rect, D3DX_FILTER_NONE, 0);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
next_tests:
hr = D3DXSaveSurfaceToFileA(NULL, D3DXIFF_BMP, surface, NULL, NULL);
ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
/* PPM and TGA are supported, even though MSDN claims they aren't */
todo_wine {
hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
todo_wine
{
hr = D3DXSaveSurfaceToFileA("saved_surface.ppm", D3DXIFF_PPM, surface, NULL, NULL);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = D3DXSaveSurfaceToFileA("saved_surface.tga", D3DXIFF_TGA, surface, NULL, NULL);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
}
hr = D3DXSaveSurfaceToFileA("saved_surface.dds", D3DXIFF_DDS, surface, NULL, NULL);
ok(hr == D3D_OK, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
if (SUCCEEDED(hr)) {
hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds", NULL, D3DX_FILTER_NONE, 0, &image_info);
ok(hr == D3D_OK, "Couldn't load saved surface %#x\n", hr);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
if (SUCCEEDED(hr)) {
ok(image_info.Width == 2, "Wrong width %u\n", image_info.Width);
ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x\n", image_info.Format);
ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u\n", image_info.ImageFileFormat);
hr = D3DXLoadSurfaceFromFileA(surface, NULL, NULL, "saved_surface.dds",
NULL, D3DX_FILTER_NONE, 0, &image_info);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Couldn't lock surface %#x\n", hr);
if (SUCCEEDED(hr)) {
ok(!memcmp(lock_rect.pBits, pixels, pitch), "Pixel data mismatch in first row\n");
ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch), "Pixel data mismatch in second row\n");
IDirect3DSurface9_UnlockRect(surface);
}
}
} else skip("Couldn't save surface\n");
ok(image_info.Width == 2, "Wrong width %u.\n", image_info.Width);
ok(image_info.Format == D3DFMT_R8G8B8, "Wrong format %#x.\n", image_info.Format);
ok(image_info.ImageFileFormat == D3DXIFF_DDS, "Wrong file format %u.\n", image_info.ImageFileFormat);
hr = IDirect3DSurface9_LockRect(surface, &lock_rect, NULL, D3DLOCK_READONLY);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(!memcmp(lock_rect.pBits, pixels, pitch),
"Pixel data mismatch in the first row.\n");
ok(!memcmp((BYTE *)lock_rect.pBits + lock_rect.Pitch, pixels + pitch, pitch),
"Pixel data mismatch in the second row.\n");
IDirect3DSurface9_UnlockRect(surface);
hr = D3DXSaveSurfaceToFileA("saved_surface", D3DXIFF_PFM + 1, surface, NULL, NULL);
ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
SetRect(&rect, 0, 0, 4, 4);
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
SetRect(&rect, 2, 0, 1, 4);
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
SetRect(&rect, 0, 2, 4, 1);
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
SetRect(&rect, -1, -1, 2, 2);
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
ok(hr == D3DERR_INVALIDCALL, "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
SetRectEmpty(&rect);
hr = D3DXSaveSurfaceToFileA("saved_surface.bmp", D3DXIFF_BMP, surface, NULL, &rect);
/* fails when debug version of d3d9 is used */
ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "D3DXSaveSurfaceToFileA returned %#x, expected %#x\n", hr, D3D_OK);
ok(hr == D3D_OK || broken(hr == D3DERR_INVALIDCALL), "Got unexpected hr %#x.\n", hr);
DeleteFileA("saved_surface.bmp");
DeleteFileA("saved_surface.ppm");

View File

@ -1353,7 +1353,7 @@ HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D f
if (FAILED(hr = IDirect3DTexture9_GetSurfaceLevel(texture, m, &surface)))
return hr;
if (FAILED(hr = lock_surface(surface, &lock_rect, &temp_surface, TRUE)))
if (FAILED(hr = lock_surface(surface, NULL, &lock_rect, &temp_surface, TRUE)))
{
IDirect3DSurface9_Release(surface);
return hr;
@ -1379,7 +1379,7 @@ HRESULT WINAPI D3DXFillTexture(struct IDirect3DTexture9 *texture, LPD3DXFILL2D f
fill_texture(format, data + y * lock_rect.Pitch + x * format->bytes_per_pixel, &value);
}
}
if (FAILED(hr = unlock_surface(surface, &lock_rect, temp_surface, TRUE)))
if (FAILED(hr = unlock_surface(surface, NULL, &lock_rect, temp_surface, TRUE)))
{
IDirect3DSurface9_Release(surface);
return hr;