[PATCH 2/6] wined3d: Refactor swapchain creation and cleanup.

Conor McCarthy cmccarthy at codeweavers.com
Mon Oct 7 23:13:50 CDT 2019


For D3D12 use in dxgi.

Signed-off-by: Conor McCarthy <cmccarthy at codeweavers.com>
---
 dlls/wined3d/swapchain.c       | 84 ++++++++++++++++++++++------------
 dlls/wined3d/wined3d.spec      |  4 ++
 dlls/wined3d/wined3d_private.h |  2 -
 include/wine/wined3d.h         |  7 +++
 4 files changed, 65 insertions(+), 32 deletions(-)

diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index 62bab65f..29e63d0e 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -29,7 +29,6 @@ WINE_DECLARE_DEBUG_CHANNEL(fps);
 
 void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain)
 {
-    HRESULT hr;
     UINT i;
 
     TRACE("Destroying swapchain %p.\n", swapchain);
@@ -61,30 +60,39 @@ void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain)
         swapchain->back_buffers = NULL;
     }
 
+    wined3d_swapchain_state_cleanup_fullscreen(&swapchain->state, swapchain->device->wined3d,
+            swapchain->device->adapter->ordinal, swapchain->device);
+}
+
+void CDECL wined3d_swapchain_state_cleanup_fullscreen(struct wined3d_swapchain_state *state,
+        struct wined3d *wined3d, unsigned int adapter_idx, struct wined3d_device *device)
+{
+    HRESULT hr;
+
     /* Restore the screen resolution if we rendered in fullscreen.
      * This will restore the screen resolution to what it was before creating
      * the swapchain. In case of d3d8 and d3d9 this will be the original
      * desktop resolution. In case of d3d7 this will be a NOP because ddraw
      * sets the resolution before starting up Direct3D, thus orig_width and
      * orig_height will be equal to the modes in the presentation params. */
-    if (!swapchain->state.desc.windowed)
+    if (!state->desc.windowed)
     {
-        if (swapchain->state.desc.auto_restore_display_mode)
+        if (state->desc.auto_restore_display_mode)
         {
-            if (FAILED(hr = wined3d_set_adapter_display_mode(swapchain->device->wined3d,
-                    swapchain->device->adapter->ordinal, &swapchain->state.original_mode)))
+            if (FAILED(hr = wined3d_set_adapter_display_mode(wined3d, adapter_idx, &state->original_mode)))
                 ERR("Failed to restore display mode, hr %#x.\n", hr);
 
-            if (swapchain->state.desc.flags & WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
+            if (state->desc.flags & WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
             {
-                wined3d_swapchain_state_restore_from_fullscreen(&swapchain->state,
-                        swapchain->state.device_window, &swapchain->state.original_window_rect);
-                wined3d_device_release_focus_window(swapchain->device);
+                wined3d_swapchain_state_restore_from_fullscreen(state,
+                        state->device_window, &state->original_window_rect);
+                if (device)
+                    wined3d_device_release_focus_window(device);
             }
         }
         else
         {
-            wined3d_swapchain_state_restore_from_fullscreen(&swapchain->state, swapchain->state.device_window, NULL);
+            wined3d_swapchain_state_restore_from_fullscreen(state, state->device_window, NULL);
         }
     }
 }
@@ -809,7 +817,6 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
     struct wined3d_resource_desc texture_desc;
     BOOL displaymode_set = FALSE;
     DWORD texture_flags = 0;
-    RECT client_rect;
     unsigned int i;
     HWND window;
     HRESULT hr;
@@ -840,27 +847,9 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
     swapchain->swap_interval = WINED3D_SWAP_INTERVAL_DEFAULT;
     swapchain_set_max_frame_latency(swapchain, device);
 
-    GetClientRect(window, &client_rect);
     if (desc->windowed)
     {
-        TRACE("Client rect %s.\n", wine_dbgstr_rect(&client_rect));
-
-        if (!desc->backbuffer_width)
-        {
-            desc->backbuffer_width = client_rect.right ? client_rect.right : 8;
-            TRACE("Updating width to %u.\n", desc->backbuffer_width);
-        }
-        if (!desc->backbuffer_height)
-        {
-            desc->backbuffer_height = client_rect.bottom ? client_rect.bottom : 8;
-            TRACE("Updating height to %u.\n", desc->backbuffer_height);
-        }
-
-        if (desc->backbuffer_format == WINED3DFMT_UNKNOWN)
-        {
-            desc->backbuffer_format = swapchain->state.original_mode.format_id;
-            TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->state.original_mode.format_id));
-        }
+        wined3d_swapchain_desc_set_backbuffer_defaults(desc, window, device->wined3d, adapter->ordinal);
     }
     else
     {
@@ -1378,6 +1367,41 @@ HRESULT CDECL wined3d_swapchain_resize_buffers(struct wined3d_swapchain *swapcha
     return WINED3D_OK;
 }
 
+void CDECL wined3d_swapchain_desc_set_backbuffer_defaults(struct wined3d_swapchain_desc *desc,
+        HWND window, const struct wined3d *wined3d, unsigned int adapter_idx)
+{
+    struct wined3d_display_mode mode;
+    RECT client_rect;
+    HRESULT hr;
+
+    GetClientRect(window, &client_rect);
+    TRACE("Client rect %s.\n", wine_dbgstr_rect(&client_rect));
+
+    if (!desc->backbuffer_width)
+    {
+        desc->backbuffer_width = client_rect.right ? client_rect.right : 8;
+        TRACE("Updating width to %u.\n", desc->backbuffer_width);
+    }
+    if (!desc->backbuffer_height)
+    {
+        desc->backbuffer_height = client_rect.bottom ? client_rect.bottom : 8;
+        TRACE("Updating height to %u.\n", desc->backbuffer_height);
+    }
+
+    if (desc->backbuffer_format == WINED3DFMT_UNKNOWN)
+    {
+        if (FAILED(hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode, NULL)))
+        {
+            WARN("Failed to get current display mode, hr %#x.\n", hr);
+        }
+        else
+        {
+            desc->backbuffer_format = mode.format_id;
+            TRACE("Updating format to %s.\n", debug_d3dformat(mode.format_id));
+        }
+    }
+}
+
 static HRESULT wined3d_swapchain_state_set_display_mode(struct wined3d_swapchain_state *state,
         struct wined3d *wined3d, unsigned int adapter_idx, struct wined3d_display_mode *mode)
 {
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index b65681f2..2fbf21b7 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -286,10 +286,14 @@
 @ cdecl wined3d_swapchain_set_palette(ptr ptr)
 @ cdecl wined3d_swapchain_set_window(ptr ptr)
 
+@ cdecl wined3d_swapchain_desc_set_backbuffer_defaults(ptr ptr)
+
+@ cdecl wined3d_swapchain_state_cleanup_fullscreen(ptr ptr long ptr)
 @ cdecl wined3d_swapchain_state_create(ptr ptr ptr long ptr)
 @ cdecl wined3d_swapchain_state_destroy(ptr)
 @ cdecl wined3d_swapchain_state_resize_target(ptr ptr long ptr)
 @ cdecl wined3d_swapchain_state_set_fullscreen(ptr ptr ptr long ptr)
+@ cdecl wined3d_swapchain_state_setup_fullscreen(ptr ptr long long)
 
 @ cdecl wined3d_texture_add_dirty_region(ptr long ptr)
 @ cdecl wined3d_texture_blt(ptr long ptr ptr long ptr long ptr long)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 307f7a42..bc853875 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -4439,8 +4439,6 @@ struct wined3d_swapchain_state
 
 void wined3d_swapchain_state_restore_from_fullscreen(struct wined3d_swapchain_state *state,
         HWND window, const RECT *window_rect) DECLSPEC_HIDDEN;
-HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state,
-        HWND window, unsigned int w, unsigned int h) DECLSPEC_HIDDEN;
 
 struct wined3d_swapchain_ops
 {
diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h
index f79cd212..69000fe4 100644
--- a/include/wine/wined3d.h
+++ b/include/wine/wined3d.h
@@ -2706,11 +2706,18 @@ HRESULT __cdecl wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain
 void __cdecl wined3d_swapchain_set_palette(struct wined3d_swapchain *swapchain, struct wined3d_palette *palette);
 void __cdecl wined3d_swapchain_set_window(struct wined3d_swapchain *swapchain, HWND window);
 
+void __cdecl wined3d_swapchain_desc_set_backbuffer_defaults(struct wined3d_swapchain_desc *desc,
+        HWND window, const struct wined3d *wined3d, unsigned int adapter_idx);
+
+void __cdecl wined3d_swapchain_state_cleanup_fullscreen(struct wined3d_swapchain_state *state,
+        struct wined3d *wined3d, unsigned int adapter_idx, struct wined3d_device *device);
 HRESULT __cdecl wined3d_swapchain_state_create(const struct wined3d_swapchain_desc *desc,
         HWND window, struct wined3d *wined3d, unsigned int adapter_idx, struct wined3d_swapchain_state **state);
 void __cdecl wined3d_swapchain_state_destroy(struct wined3d_swapchain_state *state);
 HRESULT __cdecl wined3d_swapchain_state_resize_target(struct wined3d_swapchain_state *state,
         struct wined3d *wined3d, unsigned int adapter_idx, const struct wined3d_display_mode *mode);
+HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state,
+        HWND window, unsigned int w, unsigned int h);
 HRESULT __cdecl wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_state *state,
         const struct wined3d_swapchain_desc *desc, struct wined3d *wined3d,
         unsigned int adapter_idx, const struct wined3d_display_mode *mode);
-- 
2.23.0




More information about the wine-devel mailing list