[PATCH] dxgi: 0 / 0 means 0 for a DXGI_RATIONAL

Eduard - Gabriel Munteanu eduard.munteanu at linux360.ro
Sat Nov 26 08:52:25 CST 2011


This fixes a division by zero generated in Unigine Tropics in D3D10
mode. It also adds a helper for handling such conversions.

Signed-off-by: Eduard - Gabriel Munteanu <eduard.munteanu at linux360.ro>
---
 dlls/dxgi/dxgi_private.h    |    8 ++++
 dlls/dxgi/factory.c         |    2 +-
 dlls/dxgi/tests/Makefile.in |    5 ++-
 dlls/dxgi/tests/swapchain.c |   80 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+), 3 deletions(-)
 create mode 100644 dlls/dxgi/tests/swapchain.c

diff --git a/dlls/dxgi/dxgi_private.h b/dlls/dxgi/dxgi_private.h
index 047e083..3bf4482 100644
--- a/dlls/dxgi/dxgi_private.h
+++ b/dlls/dxgi/dxgi_private.h
@@ -74,6 +74,14 @@ const char *debug_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
 
 enum wined3d_format_id wined3dformat_from_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
 
+static inline UINT dxgi_rational_to_uint(const DXGI_RATIONAL *rational)
+{
+    if (!rational->Denominator && !rational->Numerator)
+        return 0;
+
+    return rational->Numerator / rational->Denominator;
+}
+
 /* IDXGIFactory */
 struct dxgi_factory
 {
diff --git a/dlls/dxgi/factory.c b/dlls/dxgi/factory.c
index c7a11cf..f4d6ac0 100644
--- a/dlls/dxgi/factory.c
+++ b/dlls/dxgi/factory.c
@@ -221,7 +221,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IWineDXGIFactory *
     present_parameters.AutoDepthStencilFormat = 0;
     present_parameters.Flags = 0; /* WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL? */
     present_parameters.FullScreen_RefreshRateInHz =
-            desc->BufferDesc.RefreshRate.Numerator / desc->BufferDesc.RefreshRate.Denominator;
+        dxgi_rational_to_uint(&desc->BufferDesc.RefreshRate);
     present_parameters.PresentationInterval = WINED3DPRESENT_INTERVAL_DEFAULT;
 
     hr = wined3d_device_init_3d(wined3d_device, &present_parameters);
diff --git a/dlls/dxgi/tests/Makefile.in b/dlls/dxgi/tests/Makefile.in
index e66a03d..f042c2a 100644
--- a/dlls/dxgi/tests/Makefile.in
+++ b/dlls/dxgi/tests/Makefile.in
@@ -1,7 +1,8 @@
 TESTDLL   = dxgi.dll
-IMPORTS   = dxgi
+IMPORTS   = dxgi d3d10 user32
 
 C_SRCS = \
-	device.c
+	device.c \
+	swapchain.c
 
 @MAKE_TEST_RULES@
diff --git a/dlls/dxgi/tests/swapchain.c b/dlls/dxgi/tests/swapchain.c
new file mode 100644
index 0000000..4798eda
--- /dev/null
+++ b/dlls/dxgi/tests/swapchain.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2011 Eduard - Gabriel Munteanu
+ *
+ * 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 "d3d10.h"
+#include "wine/test.h"
+
+static DXGI_SWAP_CHAIN_DESC scdesc =
+{
+    /* .BufferDesc      = */
+    {
+        /* .Width            = */ 0,
+        /* .Height           = */ 0,
+        /* .RefreshRate      = */ {0, 0},   /* Tests DXGI_RATIONAL behavior for 0 / 0. */
+        /* .Format           = */ DXGI_FORMAT_R8G8B8A8_UNORM,
+        /* .ScanlineOrdering = */ DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED,
+        /* .Scaling          = */ DXGI_MODE_SCALING_UNSPECIFIED,
+    },
+    /* .SampleDesc      = */ {1, 0},
+    /* .BufferUsage     = */ DXGI_USAGE_RENDER_TARGET_OUTPUT,
+    /* .BufferCount     = */ 1,
+    /* .OutputWindow    = */ 0,     /* Set this later. */
+    /* .Windowed        = */ TRUE,
+    /* .SwapEffect      = */ DXGI_SWAP_EFFECT_DISCARD,
+    /* .Flags           = */ 0,
+};
+
+static HWND create_window(void)
+{
+    WNDCLASS wc = {0};
+    wc.lpfnWndProc = DefWindowProc;
+    wc.lpszClassName = "dxgi_test_wc";
+    RegisterClass(&wc);
+
+    return CreateWindow("dxgi_test_wc", "dxgi_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
+}
+
+static HRESULT create_device_and_swapchain(ID3D10Device **device, IDXGISwapChain **swapchain)
+{
+    HRESULT hr;
+
+    scdesc.OutputWindow = create_window();
+
+    hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE,
+                                       NULL, 0, D3D10_SDK_VERSION, &scdesc, swapchain, device);
+    if (SUCCEEDED(hr))
+        return hr;
+
+    hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_REFERENCE,
+                                       NULL, 0, D3D10_SDK_VERSION, &scdesc, swapchain, device);
+    return hr;
+}
+
+START_TEST(swapchain)
+{
+    HRESULT hr;
+    ID3D10Device *device;
+    IDXGISwapChain *swapchain;
+
+    hr = create_device_and_swapchain(&device, &swapchain);
+    ok(SUCCEEDED(hr), "Failed to create device and swapchain, hr %#x.\n", hr);
+
+    IDXGISwapChain_Release(swapchain);
+    ID3D10Device_Release(device);
+}
-- 
1.7.3.4




More information about the wine-patches mailing list