[PATCH v2 5/6] d3dx9: Use temporary surface in D3DXSaveSurfaceToFileInMemory() for unmappable textures.

Matteo Bruni mbruni at codeweavers.com
Mon Jan 14 14:45:12 CST 2019


From: Paul Gofman <gofmanp at gmail.com>

Fixes a regression triggered by commit
949dbbd31f450178c90ea8267097a975b77c3219.

Signed-off-by: Paul Gofman <gofmanp at gmail.com>
Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
---
 dlls/d3dx9_36/surface.c       | 20 ++++++++--------
 dlls/d3dx9_36/tests/surface.c | 43 +++++++++++++++++++++++++++++++----
 2 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/dlls/d3dx9_36/surface.c b/dlls/d3dx9_36/surface.c
index faac1419517..23e8f7691f2 100644
--- a/dlls/d3dx9_36/surface.c
+++ b/dlls/d3dx9_36/surface.c
@@ -530,6 +530,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)
     {
@@ -569,7 +570,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);
@@ -582,7 +583,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;
@@ -2124,6 +2125,7 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
     WICPixelFormatGUID wic_pixel_format;
     D3DFORMAT d3d_pixel_format;
     D3DSURFACE_DESC src_surface_desc;
+    IDirect3DSurface9 *temp_surface;
     D3DLOCKED_RECT locked_rect;
     int width, height;
     STATSTG stream_stats;
@@ -2131,7 +2133,7 @@ HRESULT WINAPI D3DXSaveSurfaceToFileInMemory(ID3DXBuffer **dst_buffer, D3DXIMAGE
     ID3DXBuffer *buffer;
     DWORD size;
 
-    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;
@@ -2225,16 +2227,14 @@ 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(hr = lock_surface(src_surface, &locked_rect, &temp_surface, FALSE)))
                 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 */
         {
@@ -2264,16 +2264,14 @@ 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(hr = lock_surface(src_surface, &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);
-            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 d3450722ef7..6cb1ddb73ce 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)
 {
-    HRESULT hr;
-    RECT rect;
-    ID3DXBuffer *buffer;
-    IDirect3DSurface9 *surface;
+    static const struct
+    {
+        DWORD usage;
+        D3DPOOL pool;
+    }
+    test_access_types[] =
+    {
+        {0,  D3DPOOL_MANAGED},
+        {0,  D3DPOOL_DEFAULT},
+        {D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT},
+    };
+
     struct
     {
          DWORD magic;
          struct dds_header header;
          BYTE *data;
     } *dds;
+    IDirect3DSurface9 *surface;
+    IDirect3DTexture9 *texture;
+    ID3DXBuffer *buffer;
+    unsigned int i;
+    HRESULT hr;
+    RECT rect;
 
     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, "Unexpected hr %#x, i %u.\n", hr, i);
+
+        hr = IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
+        ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i);
+
+        hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_DDS, surface, NULL, NULL);
+        ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i);
+        ID3DXBuffer_Release(buffer);
+
+        hr = D3DXSaveSurfaceToFileInMemory(&buffer, D3DXIFF_BMP, surface, NULL, NULL);
+        ok(hr == D3D_OK, "Unexpected hr %#x, i %u.\n", hr, i);
+        ID3DXBuffer_Release(buffer);
+
+        IDirect3DSurface9_Release(surface);
+        IDirect3DTexture9_Release(texture);
+    }
 }
 
 static void test_D3DXSaveSurfaceToFile(IDirect3DDevice9 *device)
-- 
2.19.2




More information about the wine-devel mailing list