[PATCH 1/2] d3d9: Return D3D_OK from the palette setters (try 2)

Stefan Dösinger stefan at codeweavers.com
Fri Jan 11 05:49:06 CST 2013


This fixes bug 28743.

try 2: Fix copyright line spaces, remove redundant memset.

I previously thought Windows returns D3DERR_INVALIDCALL if the driver
does not support any P8 surfaces or textures(i.e., AMD cards on Windows
XP). This is wrong, those cards returned INVALIDCALL because I passed
incorrect values in peFlags, not because the setters are disabled
entirely.

Windows drivers offer various amounts of non-working palette support.
AMD cards on XP do not expose any P8 formats, but the setters and
getters work. Windows 7 claims support for plain P8 surfaces, allows the
creation of DEFAULT and SYSMEM P8 surfaces and StretchRect operations
between P8 surfaces, but it does not offer a way to convert them to RGB.

I prefer to keep the stubs non-functional until we have an application
that needs more functionality than a successful return value or I can
get my hands on a GPU that supports P8 textures and allows me to write
proper tests(presumably a Geforce 2 or first-gen radeon card). At least
on Windows 7 the current palette index, but not the palettes themselves,
are recorded in the stateblock, which makes a proper implementation
non-trivial.

Also downgrade the FIXMEs in the setters to WARNs. Battlefield 1942
calls them repeatedly, but doesn't even check for P8 support or try to
create a texture.
---
 dlls/d3d9/device.c       | 13 +++++++---
 dlls/d3d9/tests/device.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index d79ad62..67f9906 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -1832,9 +1832,14 @@ static HRESULT WINAPI d3d9_device_ValidateDevice(IDirect3DDevice9Ex *iface, DWOR
 static HRESULT WINAPI d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex *iface,
         UINT palette_idx, const PALETTEENTRY *entries)
 {
-    FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
+    WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
 
-    return D3DERR_INVALIDCALL;
+    /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
+     * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
+     * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
+     *
+     * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
+    return D3D_OK;
 }
 
 static HRESULT WINAPI d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex *iface,
@@ -1847,9 +1852,9 @@ static HRESULT WINAPI d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex *iface,
 
 static HRESULT WINAPI d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT palette_idx)
 {
-    FIXME("iface %p, palette_idx %u unimplemented.\n", iface, palette_idx);
+    WARN("iface %p, palette_idx %u unimplemented.\n", iface, palette_idx);
 
-    return D3DERR_INVALIDCALL;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT *palette_idx)
diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c
index 6b977ec..00653d6 100644
--- a/dlls/d3d9/tests/device.c
+++ b/dlls/d3d9/tests/device.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2006 Vitaliy Margolen
  * Copyright (C) 2006 Chris Robinson
- * Copyright 2006-2007, 2010 Stefan Dösinger for CodeWeavers
+ * Copyright 2006-2008, 2010-2011, 2013 Stefan Dösinger for CodeWeavers
  * Copyright 2006, 2007 Henri Verbeet
  * Copyright 2013 Henri Verbeet for CodeWeavers
  * Copyright (C) 2008 Rico Schüller
@@ -4139,6 +4139,68 @@ static void test_occlusion_query_states(void)
     DestroyWindow(window);
 }
 
+static void test_set_palette(void)
+{
+    IDirect3DDevice9 *device;
+    IDirect3D9 *d3d9;
+    UINT refcount;
+    HWND window;
+    HRESULT hr;
+    PALETTEENTRY pal[256];
+    unsigned int i;
+    D3DCAPS9 caps;
+
+    if (!(d3d9 = pDirect3DCreate9(D3D_SDK_VERSION)))
+    {
+        skip("Failed to create IDirect3D9 object, skipping tests.\n");
+        return;
+    }
+
+    window = CreateWindowA("static", "d3d9_test", WS_OVERLAPPEDWINDOW,
+            0, 0, 640, 480, 0, 0, 0, 0);
+    if (!(device = create_device(d3d9, window, window, TRUE)))
+    {
+        skip("Failed to create a D3D device, skipping tests.\n");
+        DestroyWindow(window);
+        return;
+    }
+
+    for (i = 0; i < sizeof(pal) / sizeof(*pal); i++)
+    {
+        pal[i].peRed = i;
+        pal[i].peGreen = i;
+        pal[i].peBlue = i;
+        pal[i].peFlags = 0xff;
+    }
+    hr = IDirect3DDevice9_SetPaletteEntries(device, 0, pal);
+    ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
+
+    hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
+    ok(SUCCEEDED(hr), "Failed to get device caps, hr %#x.\n", hr);
+    for (i = 0; i < sizeof(pal) / sizeof(*pal); i++)
+    {
+        pal[i].peRed = i;
+        pal[i].peGreen = i;
+        pal[i].peBlue = i;
+        pal[i].peFlags = i;
+    }
+    if (caps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)
+    {
+        hr = IDirect3DDevice9_SetPaletteEntries(device, 0, pal);
+        ok(SUCCEEDED(hr), "Failed to set palette entries, hr %#x.\n", hr);
+    }
+    else
+    {
+        hr = IDirect3DDevice9_SetPaletteEntries(device, 0, pal);
+        ok(hr == D3DERR_INVALIDCALL, "SetPaletteEntries returned %#x, expected D3DERR_INVALIDCALL.\n", hr);
+    }
+
+    refcount = IDirect3DDevice9_Release(device);
+    ok(!refcount, "Device has %u references left.\n", refcount);
+    IDirect3D9_Release(d3d9);
+    DestroyWindow(window);
+}
+
 START_TEST(device)
 {
     HMODULE d3d9_handle = LoadLibraryA( "d3d9.dll" );
@@ -4203,6 +4265,7 @@ START_TEST(device)
         test_vertex_buffer_alignment();
         test_query_support();
         test_occlusion_query_states();
+        test_set_palette();
     }
 
 out:
-- 
1.7.12.4




More information about the wine-patches mailing list