From 63d0af4a9607ae31514604032a5504457ad84097 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
Date: Sat, 6 Feb 2016 01:15:07 +0100
Subject: ddraw: Don't set HWTRANSFORMANDLIGHT flag on d3d7 RGB device.

---
 dlls/ddraw/ddraw.c        |  9 +++++++++
 dlls/ddraw/tests/ddraw7.c | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index 89ce07a..64548a0 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -48,6 +48,7 @@ static struct enum_device_entry
     char interface_name[100];
     char device_name[100];
     const GUID *device_guid;
+    DWORD remove_caps;
 } device_list7[] =
 {
     /* T&L HAL device */
@@ -55,6 +56,7 @@ static struct enum_device_entry
         "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
         "Wine D3D7 T&L HAL",
         &IID_IDirect3DTnLHalDevice,
+        0,
     },
 
     /* HAL device */
@@ -62,6 +64,7 @@ static struct enum_device_entry
         "WINE Direct3D7 Hardware acceleration using WineD3D",
         "Direct3D HAL",
         &IID_IDirect3DHALDevice,
+        0,
     },
 
     /* RGB device */
@@ -69,6 +72,7 @@ static struct enum_device_entry
         "WINE Direct3D7 RGB Software Emulation using WineD3D",
         "Wine D3D7 RGB",
         &IID_IDirect3DRGBDevice,
+        D3DDEVCAPS_HWTRANSFORMANDLIGHT,
     },
 };
 
@@ -3565,6 +3569,7 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
 {
     struct ddraw *ddraw = impl_from_IDirect3D7(iface);
     D3DDEVICEDESC7 device_desc7;
+    DWORD dev_caps;
     HRESULT hr;
     size_t i;
 
@@ -3581,11 +3586,15 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
         return hr;
     }
 
+    dev_caps = device_desc7.dwDevCaps;
+
     for (i = 0; i < sizeof(device_list7)/sizeof(device_list7[0]); i++)
     {
         HRESULT ret;
 
         device_desc7.deviceGUID = *device_list7[i].device_guid;
+        device_desc7.dwDevCaps  = dev_caps & ~device_list7[i].remove_caps;
+
         ret = callback(device_list7[i].interface_name, device_list7[i].device_name, &device_desc7, context);
         if (ret != DDENUMRET_OK)
         {
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 34167c1..76dabee 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -230,6 +230,19 @@ static HRESULT WINAPI enum_devtype_cb(char *desc_str, char *name, D3DDEVICEDESC7
     return DDENUMRET_OK;
 }
 
+static HRESULT WINAPI enum_devtype_software_cb(char *desc_str, char *name, D3DDEVICEDESC7 *desc, void *ctx)
+{
+    BOOL *software_ok = ctx;
+    if (IsEqualGUID(&desc->deviceGUID, &IID_IDirect3DRGBDevice))
+    {
+        ok(!(desc->dwDevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT),
+           "RGB emulation device shouldn't have HWTRANSFORMANDLIGHT flag\n");
+        *software_ok = TRUE;
+        return DDENUMRET_CANCEL;
+    }
+    return DDENUMRET_OK;
+}
+
 static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
 {
     IDirectDrawSurface7 *surface, *ds;
@@ -240,6 +253,7 @@ static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
     IDirect3D7 *d3d7;
     HRESULT hr;
     BOOL hal_ok = FALSE;
+    BOOL software_ok = FALSE;
     const GUID *devtype = &IID_IDirect3DHALDevice;
 
     if (!(ddraw = create_ddraw()))
@@ -283,6 +297,10 @@ static IDirect3DDevice7 *create_device(HWND window, DWORD coop_level)
     ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
     if (hal_ok) devtype = &IID_IDirect3DTnLHalDevice;
 
+    hr = IDirect3D7_EnumDevices(d3d7, enum_devtype_software_cb , &software_ok);
+    ok(SUCCEEDED(hr), "Failed to enumerate devices, hr %#x.\n", hr);
+    if (!software_ok) win_skip("RGB device not found, unable to check flags\n");
+
     memset(&z_fmt, 0, sizeof(z_fmt));
     hr = IDirect3D7_EnumZBufferFormats(d3d7, devtype, enum_z_fmt, &z_fmt);
     if (FAILED(hr) || !z_fmt.dwSize)
-- 
2.7.0

