=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: dxgi: Implement dxgi_factory_CreateSwapChainForHwnd().

Alexandre Julliard julliard at winehq.org
Fri Jan 19 15:43:21 CST 2018


Module: wine
Branch: master
Commit: 729baa8a91fdc45ed66e0f8230a38a769beea87d
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=729baa8a91fdc45ed66e0f8230a38a769beea87d

Author: Józef Kucia <jkucia at codeweavers.com>
Date:   Fri Jan 19 13:30:15 2018 +0100

dxgi: Implement dxgi_factory_CreateSwapChainForHwnd().

Signed-off-by: Józef Kucia <jkucia at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dxgi/factory.c      | 151 ++++++++++++++++++++++++++++++-----------------
 dlls/dxgi/tests/device.c |   8 ++-
 2 files changed, 105 insertions(+), 54 deletions(-)

diff --git a/dlls/dxgi/factory.c b/dlls/dxgi/factory.c
index 106efb5..1d699f5 100644
--- a/dlls/dxgi/factory.c
+++ b/dlls/dxgi/factory.c
@@ -184,15 +184,90 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_GetWindowAssociation(IDXGIFactory2
 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IDXGIFactory2 *iface,
         IUnknown *device, DXGI_SWAP_CHAIN_DESC *desc, IDXGISwapChain **swapchain)
 {
+    struct dxgi_factory *factory = impl_from_IDXGIFactory2(iface);
+    DXGI_SWAP_CHAIN_FULLSCREEN_DESC fullscreen_desc;
+    DXGI_SWAP_CHAIN_DESC1 swapchain_desc;
+
+    TRACE("iface %p, device %p, desc %p, swapchain %p.\n", iface, device, desc, swapchain);
+
+    if (!desc)
+    {
+        WARN("Invalid pointer.\n");
+        return DXGI_ERROR_INVALID_CALL;
+    }
+
+    swapchain_desc.Width = desc->BufferDesc.Width;
+    swapchain_desc.Height = desc->BufferDesc.Height;
+    swapchain_desc.Format = desc->BufferDesc.Format;
+    swapchain_desc.Stereo = FALSE;
+    swapchain_desc.SampleDesc = desc->SampleDesc;
+    swapchain_desc.BufferUsage = desc->BufferUsage;
+    swapchain_desc.BufferCount = desc->BufferCount;
+    swapchain_desc.Scaling = DXGI_SCALING_STRETCH;
+    swapchain_desc.SwapEffect = desc->SwapEffect;
+    swapchain_desc.AlphaMode = DXGI_ALPHA_MODE_IGNORE;
+    swapchain_desc.Flags = desc->Flags;
+
+    fullscreen_desc.RefreshRate = desc->BufferDesc.RefreshRate;
+    fullscreen_desc.ScanlineOrdering = desc->BufferDesc.ScanlineOrdering;
+    fullscreen_desc.Scaling = desc->BufferDesc.Scaling;
+    fullscreen_desc.Windowed = desc->Windowed;
+
+    return IDXGIFactory2_CreateSwapChainForHwnd(&factory->IDXGIFactory2_iface,
+            device, desc->OutputWindow, &swapchain_desc, &fullscreen_desc, NULL,
+            (IDXGISwapChain1 **)swapchain);
+}
+
+static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSoftwareAdapter(IDXGIFactory2 *iface,
+        HMODULE swrast, IDXGIAdapter **adapter)
+{
+    FIXME("iface %p, swrast %p, adapter %p stub!\n", iface, swrast, adapter);
+
+    return E_NOTIMPL;
+}
+
+static BOOL STDMETHODCALLTYPE dxgi_factory_IsCurrent(IDXGIFactory2 *iface)
+{
+    FIXME("iface %p stub!\n", iface);
+
+    return TRUE;
+}
+
+static BOOL STDMETHODCALLTYPE dxgi_factory_IsWindowedStereoEnabled(IDXGIFactory2 *iface)
+{
+    FIXME("iface %p stub!\n", iface);
+
+    return FALSE;
+}
+
+static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChainForHwnd(IDXGIFactory2 *iface,
+        IUnknown *device, HWND window, const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc,
+        const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc,
+        IDXGIOutput *output, IDXGISwapChain1 **swapchain)
+{
     struct wined3d_swapchain *wined3d_swapchain;
     struct wined3d_swapchain_desc wined3d_desc;
     unsigned int min_buffer_count;
     IWineDXGIDevice *dxgi_device;
     HRESULT hr;
 
-    FIXME("iface %p, device %p, desc %p, swapchain %p partial stub!\n", iface, device, desc, swapchain);
+    FIXME("iface %p, device %p, window %p, swapchain_desc %p, fullscreen_desc %p, "
+            "output %p, swapchain %p partial stub!\n",
+            iface, device, window, swapchain_desc, fullscreen_desc, output, swapchain);
 
-    switch (desc->SwapEffect)
+    if (!device || !swapchain_desc || !swapchain)
+    {
+        WARN("Invalid pointer.\n");
+        return DXGI_ERROR_INVALID_CALL;
+    }
+
+    if (swapchain_desc->Stereo)
+    {
+        FIXME("Stereo swapchains are not supported.\n");
+        return DXGI_ERROR_UNSUPPORTED;
+    }
+
+    switch (swapchain_desc->SwapEffect)
     {
         case DXGI_SWAP_EFFECT_DISCARD:
         case DXGI_SWAP_EFFECT_SEQUENTIAL:
@@ -205,42 +280,46 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IDXGIFactory2 *ifa
             break;
 
         default:
-            WARN("Invalid swap effect %u used, returning DXGI_ERROR_INVALID_CALL.\n", desc->SwapEffect);
+            WARN("Invalid swap effect %u used.\n", swapchain_desc->SwapEffect);
             return DXGI_ERROR_INVALID_CALL;
     }
 
-    if (desc->BufferCount < min_buffer_count || desc->BufferCount > 16)
+    if (swapchain_desc->BufferCount < min_buffer_count || swapchain_desc->BufferCount > 16)
     {
-        WARN("BufferCount is %u, returning DXGI_ERROR_INVALID_CALL.\n", desc->BufferCount);
+        WARN("BufferCount is %u.\n", swapchain_desc->BufferCount);
         return DXGI_ERROR_INVALID_CALL;
     }
-    if (!desc->OutputWindow)
+    if (!window)
     {
         FIXME("No output window, should use factory output window.\n");
     }
 
-    hr = IUnknown_QueryInterface(device, &IID_IWineDXGIDevice, (void **)&dxgi_device);
-    if (FAILED(hr))
+    if (FAILED(hr = IUnknown_QueryInterface(device, &IID_IWineDXGIDevice, (void **)&dxgi_device)))
     {
         ERR("This is not the device we're looking for\n");
         return hr;
     }
 
-    FIXME("Ignoring SwapEffect %#x.\n", desc->SwapEffect);
-
-    wined3d_desc.backbuffer_width = desc->BufferDesc.Width;
-    wined3d_desc.backbuffer_height = desc->BufferDesc.Height;
-    wined3d_desc.backbuffer_format = wined3dformat_from_dxgi_format(desc->BufferDesc.Format);
-    wined3d_desc.backbuffer_count = desc->BufferCount;
+    if (swapchain_desc->Scaling != DXGI_SCALING_STRETCH)
+        FIXME("Ignoring scaling %#x.\n", swapchain_desc->Scaling);
+    if (swapchain_desc->SwapEffect)
+        FIXME("Ignoring swap effect %#x.\n", swapchain_desc->SwapEffect);
+    if (swapchain_desc->AlphaMode != DXGI_ALPHA_MODE_IGNORE)
+        FIXME("Ignoring alpha mode %#x.\n", swapchain_desc->AlphaMode);
+
+    wined3d_desc.backbuffer_width = swapchain_desc->Width;
+    wined3d_desc.backbuffer_height = swapchain_desc->Height;
+    wined3d_desc.backbuffer_format = wined3dformat_from_dxgi_format(swapchain_desc->Format);
+    wined3d_desc.backbuffer_count = swapchain_desc->BufferCount;
     wined3d_sample_desc_from_dxgi(&wined3d_desc.multisample_type,
-            &wined3d_desc.multisample_quality, &desc->SampleDesc);
+            &wined3d_desc.multisample_quality, &swapchain_desc->SampleDesc);
     wined3d_desc.swap_effect = WINED3D_SWAP_EFFECT_DISCARD;
-    wined3d_desc.device_window = desc->OutputWindow;
-    wined3d_desc.windowed = desc->Windowed;
+    wined3d_desc.device_window = window;
+    wined3d_desc.windowed = fullscreen_desc ? fullscreen_desc->Windowed : TRUE;
     wined3d_desc.enable_auto_depth_stencil = FALSE;
     wined3d_desc.auto_depth_stencil_format = 0;
-    wined3d_desc.flags = wined3d_swapchain_flags_from_dxgi(desc->Flags);
-    wined3d_desc.refresh_rate = dxgi_rational_to_uint(&desc->BufferDesc.RefreshRate);
+    wined3d_desc.flags = wined3d_swapchain_flags_from_dxgi(swapchain_desc->Flags);
+    wined3d_desc.refresh_rate = fullscreen_desc ? dxgi_rational_to_uint(&fullscreen_desc->RefreshRate) : 0;
     wined3d_desc.swap_interval = WINED3DPRESENT_INTERVAL_DEFAULT;
     wined3d_desc.auto_restore_display_mode = TRUE;
 
@@ -259,40 +338,6 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChain(IDXGIFactory2 *ifa
     return S_OK;
 }
 
-static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSoftwareAdapter(IDXGIFactory2 *iface,
-        HMODULE swrast, IDXGIAdapter **adapter)
-{
-    FIXME("iface %p, swrast %p, adapter %p stub!\n", iface, swrast, adapter);
-
-    return E_NOTIMPL;
-}
-
-static BOOL STDMETHODCALLTYPE dxgi_factory_IsCurrent(IDXGIFactory2 *iface)
-{
-    FIXME("iface %p stub!\n", iface);
-
-    return TRUE;
-}
-
-static BOOL STDMETHODCALLTYPE dxgi_factory_IsWindowedStereoEnabled(IDXGIFactory2 *iface)
-{
-    FIXME("iface %p stub!\n", iface);
-
-    return FALSE;
-}
-
-static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChainForHwnd(IDXGIFactory2 *iface,
-        IUnknown *device, HWND window, const DXGI_SWAP_CHAIN_DESC1 *swapchain_desc,
-        const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *fullscreen_desc,
-        IDXGIOutput *output, IDXGISwapChain1 **swapchain)
-{
-    FIXME("iface %p, device %p, window %p, swapchain_desc %p, fullscreen_desc %p, "
-            "output %p, swapchain %p stub!\n",
-            iface, device, window, swapchain_desc, fullscreen_desc, output, swapchain);
-
-    return E_NOTIMPL;
-}
-
 static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSwapChainForCoreWindow(IDXGIFactory2 *iface,
         IUnknown *device, IUnknown *window, const DXGI_SWAP_CHAIN_DESC1 *desc,
         IDXGIOutput *output, IDXGISwapChain1 **swapchain)
diff --git a/dlls/dxgi/tests/device.c b/dlls/dxgi/tests/device.c
index 7cfaea4..77b7cb7 100644
--- a/dlls/dxgi/tests/device.c
+++ b/dlls/dxgi/tests/device.c
@@ -932,8 +932,14 @@ static void test_create_swapchain(void)
     refcount = get_refcount((IUnknown *)device);
     ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
 
+    hr = IDXGIFactory_CreateSwapChain(factory, NULL, &creation_desc, &swapchain);
+    ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
+    hr = IDXGIFactory_CreateSwapChain(factory, obj, NULL, &swapchain);
+    ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
+    hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, NULL);
+    ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
     hr = IDXGIFactory_CreateSwapChain(factory, obj, &creation_desc, &swapchain);
-    ok(SUCCEEDED(hr), "CreateSwapChain failed, hr %#x.\n", hr);
+    ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
 
     refcount = get_refcount((IUnknown *)adapter);
     ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);




More information about the wine-cvs mailing list