(no subject)

wine-devel at winehq.org wine-devel at winehq.org
Sun Dec 10 15:59:05 CST 2006


>From 16f31ea1deecb26efe194429c18f112c4bf7d874 Mon Sep 17 00:00:00 2001
From: Chris Robinson <chris.kcat at gmail.com>
Date: Sun, 10 Dec 2006 13:43:08 -0800
Subject: Fix EnumAdapterModes and add a test for it
MIME-Version: 1.0
Content-Type: multipart/mixed;
  boundary="------------1.4.2.4"
To: Undisclosed.Recipients: ;
Message-Id: <200612101401.07962.chris.kcat at gmail.com>

This is a multi-part message in MIME format.
--------------1.4.2.4
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 dlls/d3d9/directx.c         |    4 +
 dlls/d3d9/tests/Makefile.in |    1 
 dlls/d3d9/tests/adapter.c   |  139 +++++++++++++++++++++++++++++++++++++++++++
 dlls/wined3d/directx.c      |   63 +++++++------------
 4 files changed, 167 insertions(+), 40 deletions(-)
--------------1.4.2.4
Content-Type: text/x-patch;
 name="16f31ea1deecb26efe194429c18f112c4bf7d874.diff"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
 filename="16f31ea1deecb26efe194429c18f112c4bf7d874.diff"

diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c
index 94f0f17..c772b1f 100644
--- a/dlls/d3d9/directx.c
+++ b/dlls/d3d9/directx.c
@@ -103,6 +103,10 @@ static UINT WINAPI IDirect3D9Impl_GetAda
 
 static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9 iface, UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
+    /* We can't pass this to WineD3D, otherwise it'll think it came from D3D8.
+       It's supposed to fail anyway, so no harm returning failure. */
+    if(Format == D3DFMT_UNKNOWN)
+        return D3DERR_INVALIDCALL;
     return IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, Format, Mode, (WINED3DDISPLAYMODE *) pMode);
 }
 
diff --git a/dlls/d3d9/tests/Makefile.in b/dlls/d3d9/tests/Makefile.in
index cab2eee..1d2cef3 100644
--- a/dlls/d3d9/tests/Makefile.in
+++ b/dlls/d3d9/tests/Makefile.in
@@ -7,6 +7,7 @@ IMPORTS   = user32 kernel32
 EXTRALIBS = -ldxerr9 -luuid -ldxguid
 
 CTESTS = \
+	adapter.c \
 	device.c \
 	shader.c \
 	stateblock.c \
diff --git a/dlls/d3d9/tests/adapter.c b/dlls/d3d9/tests/adapter.c
new file mode 100644
index 0000000..51276f1
--- /dev/null
+++ b/dlls/d3d9/tests/adapter.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2006 Henri Verbeet
+ * Copyright (C) 2006 Chris Robinson
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+#define COBJMACROS
+#include <d3d9.h>
+#include <dxerr9.h>
+#include "wine/test.h"
+
+static IDirect3D9 *init_d3d9(HMODULE d3d9_handle)
+{
+    IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
+    IDirect3D9 *d3d9_ptr = 0;
+
+    d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
+    ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
+    if (!d3d9_create) return NULL;
+
+    d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
+    ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
+
+    return d3d9_ptr;
+}
+
+/* Test adapter display modes */
+static void test_display_mode_alpha(IDirect3D9 *d3d9_ptr)
+{
+    D3DDISPLAYMODE dmode;
+
+#define TEST_FMT(x,r) do { \
+    HRESULT res = IDirect3D9_EnumAdapterModes(d3d9_ptr, 0, (x), 0, &dmode); \
+    ok(res==(r), "EnumAdapterModes("#x") did not return "#r" (got %s)!\n", DXGetErrorString9(res)); \
+} while(0)
+
+    memset(&dmode, 0xDD, sizeof(dmode)); \
+
+    TEST_FMT(D3DFMT_X1R5G5B5, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_R8G8B8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A8R8G8B8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A1R5G5B5, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A4R4G4B4, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_R3G3B2, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A8R3G3B2, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_X4R4G4B4, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A2B10G10R10, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A8B8G8R8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_X8B8G8R8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_G16R16, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A2R10G10B10, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A16B16G16R16, D3DERR_INVALIDCALL);
+
+    TEST_FMT(D3DFMT_A8P8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_P8, D3DERR_INVALIDCALL);
+
+    TEST_FMT(D3DFMT_L8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A8L8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A4L4, D3DERR_INVALIDCALL);
+
+    TEST_FMT(D3DFMT_V8U8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_L6V5U5, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_X8L8V8U8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_Q8W8V8U8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_V16U16, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_W11V11U10, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A2W10V10U10, D3DERR_INVALIDCALL);
+
+    TEST_FMT(D3DFMT_UYVY, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_YUY2, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_DXT1, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_DXT2, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_DXT3, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_DXT4, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_DXT5, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_MULTI2_ARGB, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_G8R8_G8B8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_R8G8_B8G8, D3DERR_INVALIDCALL);
+
+    TEST_FMT(D3DFMT_D16_LOCKABLE, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D32, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D15S1, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D24S8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D24X8, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D24X4S4, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D16, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_L16, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D32F_LOCKABLE, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_D24FS8, D3DERR_INVALIDCALL);
+
+    TEST_FMT(D3DFMT_VERTEXDATA, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_INDEX16, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_INDEX32, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_Q16W16V16U16, D3DERR_INVALIDCALL);
+    /* Flaoting point formats */
+    TEST_FMT(D3DFMT_R16F, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_G16R16F, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A16B16G16R16F, D3DERR_INVALIDCALL);
+
+    /* IEEE formats */
+    TEST_FMT(D3DFMT_R32F, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_G32R32F, D3DERR_INVALIDCALL);
+    TEST_FMT(D3DFMT_A32B32G32R32F, D3DERR_INVALIDCALL);
+
+    TEST_FMT(D3DFMT_CxV8U8, D3DERR_INVALIDCALL);
+
+    TEST_FMT(0, D3DERR_INVALIDCALL);
+}
+
+START_TEST(adapter)
+{
+    HMODULE d3d9_handle;
+    IDirect3D9 *d3d9_ptr;
+
+    d3d9_handle = LoadLibraryA("d3d9.dll");
+    if (!d3d9_handle)
+    {
+        trace("Could not load d3d9.dll, skipping tests\n");
+        return;
+    }
+
+    d3d9_ptr = init_d3d9(d3d9_handle);
+    if (!d3d9_ptr) return;
+
+    test_display_mode_alpha(d3d9_ptr);
+}
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 59f8c83..4e5762d 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -1075,11 +1075,6 @@ static UINT     WINAPI IWineD3DImpl_GetA
 #if !defined( DEBUG_SINGLE_MODE )
         DEVMODEW DevModeW;
 
-        /* Work out the current screen bpp */
-        HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
-        int bpp = GetDeviceCaps(hdc, BITSPIXEL);
-        DeleteDC(hdc);
-
         while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
             j++;
             switch (Format)
@@ -1088,14 +1083,10 @@ #if !defined( DEBUG_SINGLE_MODE )
                    i++;
                    break;
             case WINED3DFMT_X8R8G8B8:
-            case WINED3DFMT_A8R8G8B8:
-                   if (min(DevModeW.dmBitsPerPel, bpp) == 32) i++;
-                   if (min(DevModeW.dmBitsPerPel, bpp) == 24) i++;
+                   if (DevModeW.dmBitsPerPel == 32) i++;
                    break;
-            case WINED3DFMT_X1R5G5B5:
-            case WINED3DFMT_A1R5G5B5:
             case WINED3DFMT_R5G6B5:
-                   if (min(DevModeW.dmBitsPerPel, bpp) == 16) i++;
+                   if (DevModeW.dmBitsPerPel == 16) i++;
                    break;
             default:
                    /* Skip other modes as they do not match the requested format */
@@ -1127,50 +1118,42 @@ static HRESULT WINAPI IWineD3DImpl_EnumA
     }
 
     if (Adapter == 0) { /* Display */
-        int bpp;
 #if !defined( DEBUG_SINGLE_MODE )
         DEVMODEW DevModeW;
         int ModeIdx = 0;
 
-        /* Work out the current screen bpp */
-        HDC hdc = CreateDCA("DISPLAY", NULL, NULL, NULL);
-        bpp = GetDeviceCaps(hdc, BITSPIXEL);
-        DeleteDC(hdc);
-
         /* If we are filtering to a specific format, then need to skip all unrelated
            modes, but if mode is irrelevant, then we can use the index directly      */
         if (Format == WINED3DFMT_UNKNOWN)
         {
             ModeIdx = Mode;
-        } else {
+        }
+        else {
             int i = 0;
             int j = 0;
             DEVMODEW DevModeWtmp;
 
-
-            while (i<(Mode) && EnumDisplaySettingsExW(NULL, j, &DevModeWtmp, 0)) {
-                j++;
+            while (EnumDisplaySettingsExW(NULL, j++, &DevModeWtmp, 0) && (i<=Mode)) {
                 switch (Format)
                 {
-                case WINED3DFMT_UNKNOWN:
-                       i++;
-                       break;
                 case WINED3DFMT_X8R8G8B8:
-                case WINED3DFMT_A8R8G8B8:
-                       if (min(DevModeWtmp.dmBitsPerPel, bpp) == 32) i++;
-                       if (min(DevModeWtmp.dmBitsPerPel, bpp) == 24) i++;
+                       if (DevModeWtmp.dmBitsPerPel == 32) i++;
                        break;
-                case WINED3DFMT_X1R5G5B5:
-                case WINED3DFMT_A1R5G5B5:
                 case WINED3DFMT_R5G6B5:
-                       if (min(DevModeWtmp.dmBitsPerPel, bpp) == 16) i++;
+                       if (DevModeWtmp.dmBitsPerPel == 16) i++;
                        break;
                 default:
-                       /* Skip other modes as they do not match requested format */
-                       break;
+                       /* Modes that don't match what we support can get an early-out */
+                       TRACE_(d3d_caps)("Searching for %s, returning D3DERR_INVALIDCALL\n", debug_d3dformat(Format));
+                       return WINED3DERR_INVALIDCALL;
                 }
             }
-            ModeIdx = j;
+
+            if (i == 0) {
+                TRACE_(d3d_caps)("No modes found for format (%x - %s)\n", Format, debug_d3dformat(Format));
+                return WINED3DERR_INVALIDCALL;
+            }
+            ModeIdx = j - 1;
         }
 
         /* Now get the display mode via the calculated index */
@@ -1178,7 +1161,6 @@ #if !defined( DEBUG_SINGLE_MODE )
         {
             pMode->Width        = DevModeW.dmPelsWidth;
             pMode->Height       = DevModeW.dmPelsHeight;
-            bpp                 = min(DevModeW.dmBitsPerPel, bpp);
             pMode->RefreshRate  = D3DADAPTER_DEFAULT;
             if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
             {
@@ -1187,12 +1169,13 @@ #if !defined( DEBUG_SINGLE_MODE )
 
             if (Format == WINED3DFMT_UNKNOWN)
             {
-                switch (bpp) {
+                switch (DevModeW.dmBitsPerPel) {
                 case  8: pMode->Format = WINED3DFMT_R3G3B2;   break;
                 case 16: pMode->Format = WINED3DFMT_R5G6B5;   break;
-                case 24: /* Robots and EVE Online need 24 and 32 bit as A8R8G8B8 to start */
-                case 32: pMode->Format = WINED3DFMT_A8R8G8B8; break;
-                default: pMode->Format = WINED3DFMT_UNKNOWN;
+                case 32: pMode->Format = WINED3DFMT_X8R8G8B8; break;
+                default:
+                       pMode->Format = WINED3DFMT_UNKNOWN;
+                       ERR("Unhandled D3D bit depth (%u) in mode list!\n", DevModeW.dmBitsPerPel);
                 }
             } else {
                 pMode->Format = Format;
@@ -1211,10 +1194,10 @@ #else
         pMode->Height       = 600;
         pMode->RefreshRate  = D3DADAPTER_DEFAULT;
         pMode->Format       = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_A8R8G8B8 : Format;
-        bpp = 32;
 #endif
         TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
-                 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format), bpp);
+                 pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
+                 DevModeW.dmBitsPerPel);
 
     } else {
         FIXME_(d3d_caps)("Adapter not primary display\n");

--------------1.4.2.4--





More information about the wine-patches mailing list