Henri Verbeet : d3d9: Introduce a separate function for swapchain creation.

Alexandre Julliard julliard at winehq.org
Wed Apr 11 12:56:46 CDT 2012


Module: wine
Branch: master
Commit: 8b95d8d2e3f3faba7c928386b173825bb77bc364
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8b95d8d2e3f3faba7c928386b173825bb77bc364

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Tue Apr 10 22:06:19 2012 +0200

d3d9: Introduce a separate function for swapchain creation.

---

 dlls/d3d9/d3d9_private.h |    4 ++--
 dlls/d3d9/device.c       |   30 +++++++-----------------------
 dlls/d3d9/swapchain.c    |   27 ++++++++++++++++++++++++++-
 3 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index 7d1821c..f0262f5 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -211,8 +211,8 @@ typedef struct IDirect3DSwapChain9Impl
     IDirect3DDevice9Ex *parentDevice;
 } IDirect3DSwapChain9Impl;
 
-HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
-        D3DPRESENT_PARAMETERS *present_parameters) DECLSPEC_HIDDEN;
+HRESULT d3d9_swapchain_create(IDirect3DDevice9Impl *device, D3DPRESENT_PARAMETERS *present_parameters,
+        IDirect3DSwapChain9Impl **swapchain) DECLSPEC_HIDDEN;
 
 /* ----------------- */
 /* IDirect3DSurface9 */
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index bec3c4b..f828d26 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -443,32 +443,17 @@ static BOOL WINAPI IDirect3DDevice9Impl_ShowCursor(IDirect3DDevice9Ex *iface, BO
 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
         D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
 {
-    IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DDevice9Impl *device = impl_from_IDirect3DDevice9Ex(iface);
     IDirect3DSwapChain9Impl *object;
     HRESULT hr;
 
     TRACE("iface %p, present_parameters %p, swapchain %p.\n",
             iface, present_parameters, swapchain);
 
-    object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
-    {
-        ERR("Failed to allocate swapchain memory.\n");
-        return E_OUTOFMEMORY;
-    }
+    if (SUCCEEDED(hr = d3d9_swapchain_create(device, present_parameters, &object)))
+        *swapchain = (IDirect3DSwapChain9 *)object;
 
-    hr = swapchain_init(object, This, present_parameters);
-    if (FAILED(hr))
-    {
-        WARN("Failed to initialize swapchain, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
-        return hr;
-    }
-
-    TRACE("Created swapchain %p.\n", object);
-    *swapchain = (IDirect3DSwapChain9 *)object;
-
-    return D3D_OK;
+    return hr;
 }
 
 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface,
@@ -3291,7 +3276,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent
 {
     struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent);
     D3DPRESENT_PARAMETERS local_parameters;
-    IDirect3DSwapChain9 *d3d_swapchain;
+    IDirect3DSwapChain9Impl *d3d_swapchain;
     HRESULT hr;
 
     TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent, desc, swapchain);
@@ -3312,8 +3297,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent
     local_parameters.FullScreen_RefreshRateInHz = desc->refresh_rate;
     local_parameters.PresentationInterval = desc->swap_interval;
 
-    hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain(&device->IDirect3DDevice9Ex_iface,
-            &local_parameters, &d3d_swapchain);
+    hr = d3d9_swapchain_create(device, &local_parameters, &d3d_swapchain);
     if (FAILED(hr))
     {
         WARN("Failed to create swapchain, hr %#x.\n", hr);
@@ -3321,7 +3305,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent
         return hr;
     }
 
-    *swapchain = ((IDirect3DSwapChain9Impl *)d3d_swapchain)->wined3d_swapchain;
+    *swapchain = d3d_swapchain->wined3d_swapchain;
     wined3d_swapchain_incref(*swapchain);
     IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
 
diff --git a/dlls/d3d9/swapchain.c b/dlls/d3d9/swapchain.c
index 7a13848..8cbecdd 100644
--- a/dlls/d3d9/swapchain.c
+++ b/dlls/d3d9/swapchain.c
@@ -237,7 +237,7 @@ static const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops =
     d3d9_swapchain_wined3d_object_released,
 };
 
-HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
+static HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
         D3DPRESENT_PARAMETERS *present_parameters)
 {
     struct wined3d_swapchain_desc desc;
@@ -294,3 +294,28 @@ HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl
 
     return D3D_OK;
 }
+
+HRESULT d3d9_swapchain_create(IDirect3DDevice9Impl *device, D3DPRESENT_PARAMETERS *present_parameters,
+        IDirect3DSwapChain9Impl **swapchain)
+{
+    IDirect3DSwapChain9Impl *object;
+    HRESULT hr;
+
+    if (!(object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object))))
+    {
+        ERR("Failed to allocate swapchain memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    if (FAILED(hr = swapchain_init(object, device, present_parameters)))
+    {
+        WARN("Failed to initialize swapchain, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created swapchain %p.\n", object);
+    *swapchain = object;
+
+    return D3D_OK;
+}




More information about the wine-cvs mailing list