[PATCH 5/6] d3dx9: d3dx9: Use temporary surface in D3DXSaveSurfaceToFileInMemory() for unmappable textures.
Paul Gofman
gofmanp at gmail.com
Mon Jan 14 06:12:26 CST 2019
Fixes a regression triggered by commit 949dbbd31f450178c90ea8267097a975b77c3219.
Signed-off-by: Paul Gofman <gofmanp at gmail.com>
---
dlls/d3dx9_36/surface.c | 20 +++++++++-----------
dlls/d3dx9_36/tests/surface.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c
index 68c14e88e0..3f00d80080 100644
--- a/dlls/d3dx9_36/surface.c
+++ b/dlls/d3dx9_36/surface.c
@@ -533,6 +533,7 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSur
BYTE *pixels;
struct volume volume;
const struct pixel_format_desc *pixel_format;
+ IDirect3DSurface9 *temp_surface;
if (src_rect)
{
@@ -572,7 +573,7 @@ static HRESULT save_dds_surface_to_memory(ID3DXBuffer **dst_buffer, IDirect3DSur
return hr;
}
- hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, NULL, D3DLOCK_READONLY);
+ hr = lock_surface(src_surface, &locked_rect, &temp_surface, FALSE);
if (FAILED(hr))
{
ID3DXBuffer_Release(buffer);
@@ -585,7 +586,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);
- IDirect3DSurface9_UnlockRect(src_surface);
+ unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
*dst_buffer = buffer;
return D3D_OK;
@@ -2133,8 +2134,9 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
HGLOBAL stream_hglobal;
ID3DXBuffer *buffer;
DWORD size;
+ IDirect3DSurface9 *temp_surface;
- TRACE("(%p, %#x, %p, %p, %s)\n",
+ TRACE("dst_buffer %p, file_format %#x, src_surface %p, src_palette %p, src_rect %s.\n",
dst_buffer, file_format, src_surface, src_palette, wine_dbgstr_rect(src_rect));
if (!dst_buffer || !src_surface) return D3DERR_INVALIDCALL;
@@ -2228,18 +2230,16 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
if (SUCCEEDED(hr) && d3d_pixel_format != D3DFMT_UNKNOWN)
{
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 */
{
- hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
- if (FAILED(hr))
+ if (FAILED(lock_surface(src_surface, &locked_rect, &temp_surface, FALSE)))
{
hr = D3DERR_INVALIDCALL;
goto cleanup;
}
IWICBitmapFrameEncode_WritePixels(frame, height,
locked_rect.Pitch, height * locked_rect.Pitch, locked_rect.pBits);
- IDirect3DSurface9_UnlockRect(src_surface);
+ unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
}
else /* Pixel format conversion */
{
@@ -2269,9 +2269,7 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
hr = E_OUTOFMEMORY;
goto cleanup;
}
-
- hr = IDirect3DSurface9_LockRect(src_surface, &locked_rect, src_rect, D3DLOCK_READONLY);
- if (FAILED(hr))
+ if (FAILED(lock_surface(src_surface, &locked_rect, &temp_surface, FALSE)))
{
HeapFree(GetProcessHeap(), 0, dst_data);
hr = D3DERR_INVALIDCALL;
@@ -2279,7 +2277,7 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
}
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);
- IDirect3DSurface9_UnlockRect(src_surface);
+ unlock_surface(src_surface, &locked_rect, temp_surface, FALSE);
IWICBitmapFrameEncode_WritePixels(frame, height, dst_pitch, dst_pitch * height, dst_data);
HeapFree(GetProcessHeap(), 0, dst_data);
diff --git a/dlls/d3dx9_36/tests/surface.c b/dlls/d3dx9_36/tests/surface.c
index d3450722ef..3ce7b0dafd 100644
--- a/dlls/d3dx9_36/tests/surface.c
+++ b/dlls/d3dx9_36/tests/surface.c
@@ -1253,16 +1253,30 @@ static void test_D3DXLoadSurface(IDirect3DDevice9 *device)
static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
{
+ static const struct
+ {
+ DWORD usage;
+ D3DPOOL pool;
+ }
+ test_access_types[] =
+ {
+ {0, D3DPOOL_MANAGED},
+ {0, D3DPOOL_DEFAULT},
+ {D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT},
+ };
+
HRESULT hr;
RECT rect;
ID3DXBuffer *buffer;
IDirect3DSurface9 *surface;
+ IDirect3DTexture9 *texture;
struct
{
DWORD magic;
struct dds_header header;
BYTE *data;
} *dds;
+ unsigned int i;
hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 4, 4, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &surface, NULL);
if (FAILED(hr)) {
@@ -1317,6 +1331,27 @@ static void test_D3DXSaveSurfaceToFileInMemory(IDirect3DDevice9 *device)
ID3DXBuffer_Release(buffer);
IDirect3DSurface9_Release(surface);
+
+ for (i = 0; i < ARRAY_SIZE(test_access_types); ++i)
+ {
+ hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 0, test_access_types[i].usage,
+ D3DFMT_A8R8G8B8, test_access_types[i].pool, &texture, NULL);
+ ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture failed, hr %#x, i %u.\n", hr, i);
+
+ hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
+ ok(hr == D3D_OK, "IDirect3DTexture9_GetSurfaceLevel failed, hr %#x, i %u.\n", hr, i);
+
+ hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, NULL, NULL);
+ ok(hr == D3D_OK, "D3DXSaveSurfaceToFileInMemory failed, hr %#x, i %u.\n", hr, i);
+ ID3DXBuffer_Release(buffer);
+
+ hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, NULL);
+ ok(hr == D3D_OK, "D3DXSaveSurfaceToFileInMemory failed, hr %#x, i %u.\n", hr, i);
+ ID3DXBuffer_Release(buffer);
+
+ IDirect3DSurface9_Release(surface);
+ IDirect3DTexture9_Release(texture);
+ }
}
static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
--
2.20.1
More information about the wine-devel
mailing list