[PATCH 2/4] ddraw: Subtract framebuffer size from reported available video memory.

Józef Kucia jkucia at codeweavers.com
Sat Dec 17 17:22:26 CST 2016


Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
---

For bug 40477.

---
 dlls/ddraw/ddraw.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index c9efba6..ef6eb3f 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -1896,6 +1896,9 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C
         DWORD *free)
 {
     struct ddraw *ddraw = impl_from_IDirectDraw7(iface);
+    struct wined3d_display_mode mode;
+    INT64 total_vidmem, free_vidmem;
+    unsigned int framebuffer_size;
     HRESULT hr = DD_OK;
 
     TRACE("iface %p, caps %p, total %p, free %p.\n", iface, Caps, total, free);
@@ -1918,14 +1921,34 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C
         return DDERR_INVALIDPARAMS;
     }
 
+    /* Some applications (e.g. 3DMark 2000) assume that the reported amount of
+     * video memory doesn't include the memory used by the default framebuffer.
+     */
+    if (FAILED(hr = wined3d_get_adapter_display_mode(ddraw->wined3d, WINED3DADAPTER_DEFAULT, &mode, NULL)))
+    {
+        WARN("Failed to get display mode, hr %#x.\n", hr);
+        wined3d_mutex_unlock();
+        return hr;
+    }
+    framebuffer_size = wined3d_calculate_format_pitch(ddraw->wined3d, WINED3DADAPTER_DEFAULT,
+            mode.format_id, mode.width);
+    framebuffer_size *= mode.height;
+
     if (free)
-        *free = wined3d_device_get_available_texture_mem(ddraw->wined3d_device);
+    {
+        free_vidmem = wined3d_device_get_available_texture_mem(ddraw->wined3d_device);
+        *free = max(0, free_vidmem - framebuffer_size);
+        TRACE("Free video memory %#x.\n", *free);
+    }
+
     if (total)
     {
         struct wined3d_adapter_identifier desc = {0};
 
         hr = wined3d_get_adapter_identifier(ddraw->wined3d, WINED3DADAPTER_DEFAULT, 0, &desc);
-        *total = min(UINT_MAX, desc.video_memory);
+        total_vidmem = min(UINT_MAX, desc.video_memory);
+        *total = max(0, total_vidmem - framebuffer_size);
+        TRACE("Total video memory %#x.\n", *total);
     }
 
     wined3d_mutex_unlock();
-- 
2.7.3




More information about the wine-patches mailing list