[PATCH 1/2] wined3d: Introduce a separate function to resize swapchain buffers.
Henri Verbeet
hverbeet at codeweavers.com
Fri Aug 7 03:01:33 CDT 2015
---
dlls/wined3d/device.c | 202 ++++++++++++-----------------------------
dlls/wined3d/swapchain.c | 94 ++++++++++++++++++-
dlls/wined3d/wined3d_private.h | 4 +-
3 files changed, 155 insertions(+), 145 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index c746d18..6d2f8aa 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4432,14 +4432,10 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
const struct wined3d_swapchain_desc *swapchain_desc, const struct wined3d_display_mode *mode,
wined3d_device_reset_cb callback, BOOL reset_state)
{
- enum wined3d_format_id backbuffer_format = swapchain_desc->backbuffer_format;
struct wined3d_resource *resource, *cursor;
struct wined3d_swapchain *swapchain;
struct wined3d_display_mode m;
BOOL DisplayModeChanged;
- BOOL update_desc = FALSE;
- UINT backbuffer_width = swapchain_desc->backbuffer_width;
- UINT backbuffer_height = swapchain_desc->backbuffer_height;
HRESULT hr = WINED3D_OK;
unsigned int i;
@@ -4492,13 +4488,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
}
}
- /* Is it necessary to recreate the gl context? Actually every setting can be changed
- * on an existing gl context, so there's no real need for recreation.
- *
- * TODO: Figure out how Reset influences resources in D3DPOOL_DEFAULT, D3DPOOL_SYSTEMMEMORY and D3DPOOL_MANAGED
- *
- * TODO: Figure out what happens to explicit swapchains, or if we have more than one implicit swapchain
- */
TRACE("New params:\n");
TRACE("backbuffer_width %u\n", swapchain_desc->backbuffer_width);
TRACE("backbuffer_height %u\n", swapchain_desc->backbuffer_height);
@@ -4526,11 +4515,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
swapchain->desc.swap_interval = swapchain_desc->swap_interval;
swapchain->desc.auto_restore_display_mode = swapchain_desc->auto_restore_display_mode;
- /* What to do about these? */
- if (swapchain_desc->backbuffer_count
- && swapchain_desc->backbuffer_count != swapchain->desc.backbuffer_count)
- FIXME("Cannot change the back buffer count yet.\n");
-
if (swapchain_desc->device_window
&& swapchain_desc->device_window != swapchain->desc.device_window)
{
@@ -4557,81 +4541,78 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
m.refresh_rate = swapchain_desc->refresh_rate;
m.format_id = swapchain_desc->backbuffer_format;
m.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
+
+ if ((m.width != swapchain->desc.backbuffer_width
+ || m.height != swapchain->desc.backbuffer_height))
+ DisplayModeChanged = TRUE;
}
- if (!backbuffer_width || !backbuffer_height)
+ if (!swapchain_desc->windowed != !swapchain->desc.windowed
+ || DisplayModeChanged)
{
- /* The application is requesting that either the swapchain width or
- * height be set to the corresponding dimension in the window's
- * client rect. */
-
- RECT client_rect;
-
- if (!swapchain_desc->windowed)
- return WINED3DERR_INVALIDCALL;
-
- if (!GetClientRect(swapchain->device_window, &client_rect))
+ if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &m)))
{
- ERR("Failed to get client rect, last error %#x.\n", GetLastError());
+ WARN("Failed to set display mode, hr %#x.\n", hr);
return WINED3DERR_INVALIDCALL;
}
- if (!backbuffer_width)
- backbuffer_width = client_rect.right;
-
- if (!backbuffer_height)
- backbuffer_height = client_rect.bottom;
- }
-
- if (backbuffer_width != swapchain->desc.backbuffer_width
- || backbuffer_height != swapchain->desc.backbuffer_height)
- {
- if (!swapchain_desc->windowed)
- DisplayModeChanged = TRUE;
-
- swapchain->desc.backbuffer_width = backbuffer_width;
- swapchain->desc.backbuffer_height = backbuffer_height;
- update_desc = TRUE;
- }
-
- if (backbuffer_format == WINED3DFMT_UNKNOWN)
- {
if (!swapchain_desc->windowed)
- return WINED3DERR_INVALIDCALL;
- backbuffer_format = swapchain->original_mode.format_id;
- }
+ {
+ if (swapchain->desc.windowed)
+ {
+ HWND focus_window = device->create_parms.focus_window;
+ if (!focus_window)
+ focus_window = swapchain_desc->device_window;
+ if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window)))
+ {
+ ERR("Failed to acquire focus window, hr %#x.\n", hr);
+ return hr;
+ }
- if (backbuffer_format != swapchain->desc.backbuffer_format)
- {
- swapchain->desc.backbuffer_format = backbuffer_format;
- update_desc = TRUE;
+ /* switch from windowed to fs */
+ wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
+ swapchain_desc->backbuffer_width,
+ swapchain_desc->backbuffer_height);
+ }
+ else
+ {
+ /* Fullscreen -> fullscreen mode change */
+ MoveWindow(swapchain->device_window, 0, 0,
+ swapchain_desc->backbuffer_width,
+ swapchain_desc->backbuffer_height,
+ TRUE);
+ }
+ swapchain->d3d_mode = m;
+ }
+ else if (!swapchain->desc.windowed)
+ {
+ /* Fullscreen -> windowed switch */
+ wined3d_device_restore_fullscreen_window(device, swapchain->device_window);
+ wined3d_device_release_focus_window(device);
+ }
+ swapchain->desc.windowed = swapchain_desc->windowed;
}
-
- if (swapchain_desc->multisample_type != swapchain->desc.multisample_type
- || swapchain_desc->multisample_quality != swapchain->desc.multisample_quality)
+ else if (!swapchain_desc->windowed)
{
- swapchain->desc.multisample_type = swapchain_desc->multisample_type;
- swapchain->desc.multisample_quality = swapchain_desc->multisample_quality;
- update_desc = TRUE;
+ DWORD style = device->style;
+ DWORD exStyle = device->exStyle;
+ /* If we're in fullscreen, and the mode wasn't changed, we have to get the window back into
+ * the right position. Some applications(Battlefield 2, Guild Wars) move it and then call
+ * Reset to clear up their mess. Guild Wars also loses the device during that.
+ */
+ device->style = 0;
+ device->exStyle = 0;
+ wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
+ swapchain_desc->backbuffer_width,
+ swapchain_desc->backbuffer_height);
+ device->style = style;
+ device->exStyle = exStyle;
}
- if (update_desc)
- {
- UINT i;
-
- if (FAILED(hr = wined3d_texture_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
- swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
- swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
- return hr;
-
- for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
- {
- if (FAILED(hr = wined3d_texture_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
- swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
- swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
- return hr;
- }
- }
+ if (FAILED(hr = wined3d_swapchain_resize_buffers(swapchain, swapchain_desc->backbuffer_count,
+ swapchain_desc->backbuffer_width, swapchain_desc->backbuffer_height, swapchain_desc->backbuffer_format,
+ swapchain_desc->multisample_type, swapchain_desc->multisample_quality)))
+ return hr;
if (device->auto_depth_stencil_view)
{
@@ -4688,68 +4669,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
return hr;
}
- if (!swapchain_desc->windowed != !swapchain->desc.windowed
- || DisplayModeChanged)
- {
- if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, &m)))
- {
- WARN("Failed to set display mode, hr %#x.\n", hr);
- return WINED3DERR_INVALIDCALL;
- }
-
- if (!swapchain_desc->windowed)
- {
- if (swapchain->desc.windowed)
- {
- HWND focus_window = device->create_parms.focus_window;
- if (!focus_window)
- focus_window = swapchain_desc->device_window;
- if (FAILED(hr = wined3d_device_acquire_focus_window(device, focus_window)))
- {
- ERR("Failed to acquire focus window, hr %#x.\n", hr);
- return hr;
- }
-
- /* switch from windowed to fs */
- wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
- swapchain_desc->backbuffer_width,
- swapchain_desc->backbuffer_height);
- }
- else
- {
- /* Fullscreen -> fullscreen mode change */
- MoveWindow(swapchain->device_window, 0, 0,
- swapchain_desc->backbuffer_width,
- swapchain_desc->backbuffer_height,
- TRUE);
- }
- swapchain->d3d_mode = m;
- }
- else if (!swapchain->desc.windowed)
- {
- /* Fullscreen -> windowed switch */
- wined3d_device_restore_fullscreen_window(device, swapchain->device_window);
- wined3d_device_release_focus_window(device);
- }
- swapchain->desc.windowed = swapchain_desc->windowed;
- }
- else if (!swapchain_desc->windowed)
- {
- DWORD style = device->style;
- DWORD exStyle = device->exStyle;
- /* If we're in fullscreen, and the mode wasn't changed, we have to get the window back into
- * the right position. Some applications(Battlefield 2, Guild Wars) move it and then call
- * Reset to clear up their mess. Guild Wars also loses the device during that.
- */
- device->style = 0;
- device->exStyle = 0;
- wined3d_device_setup_fullscreen_window(device, swapchain->device_window,
- swapchain_desc->backbuffer_width,
- swapchain_desc->backbuffer_height);
- device->style = style;
- device->exStyle = exStyle;
- }
-
wine_rb_clear(&device->samplers, device_free_sampler, NULL);
if (reset_state)
@@ -4794,9 +4713,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
wined3d_cs_emit_set_scissor_rect(device->cs, &state->scissor_rect);
}
- swapchain_update_render_to_fbo(swapchain);
- swapchain_update_draw_bindings(swapchain);
-
if (reset_state && device->d3d_initialized)
hr = create_primary_opengl_context(device, swapchain);
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index 5a5ba6b..6630ea6 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -731,7 +731,7 @@ static const struct wined3d_swapchain_ops swapchain_gdi_ops =
swapchain_gdi_present,
};
-void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain)
+static void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain)
{
RECT client_rect;
@@ -1224,3 +1224,95 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa
device->filter_messages = filter_messages;
}
+
+HRESULT wined3d_swapchain_resize_buffers(struct wined3d_swapchain *swapchain, unsigned int buffer_count,
+ unsigned int width, unsigned int height, enum wined3d_format_id format_id,
+ enum wined3d_multisample_type multisample_type, unsigned int multisample_quality)
+{
+ BOOL update_desc = FALSE;
+
+ TRACE("swapchain %p, buffer_count %u, width %u, height %u, format %s, "
+ "multisample_type %#x, multisample_quality %#x.\n",
+ swapchain, buffer_count, width, height, debug_d3dformat(format_id),
+ multisample_type, multisample_quality);
+
+ if (buffer_count && buffer_count != swapchain->desc.backbuffer_count)
+ FIXME("Cannot change the back buffer count yet.\n");
+
+ if (!width || !height)
+ {
+ /* The application is requesting that either the swapchain width or
+ * height be set to the corresponding dimension in the window's
+ * client rect. */
+
+ RECT client_rect;
+
+ if (!swapchain->desc.windowed)
+ return WINED3DERR_INVALIDCALL;
+
+ if (!GetClientRect(swapchain->device_window, &client_rect))
+ {
+ ERR("Failed to get client rect, last error %#x.\n", GetLastError());
+ return WINED3DERR_INVALIDCALL;
+ }
+
+ if (!width)
+ width = client_rect.right;
+
+ if (!height)
+ height = client_rect.bottom;
+ }
+
+ if (width != swapchain->desc.backbuffer_width
+ || height != swapchain->desc.backbuffer_height)
+ {
+ swapchain->desc.backbuffer_width = width;
+ swapchain->desc.backbuffer_height = height;
+ update_desc = TRUE;
+ }
+
+ if (format_id == WINED3DFMT_UNKNOWN)
+ {
+ if (!swapchain->desc.windowed)
+ return WINED3DERR_INVALIDCALL;
+ format_id = swapchain->original_mode.format_id;
+ }
+
+ if (format_id != swapchain->desc.backbuffer_format)
+ {
+ swapchain->desc.backbuffer_format = format_id;
+ update_desc = TRUE;
+ }
+
+ if (multisample_type != swapchain->desc.multisample_type
+ || multisample_quality != swapchain->desc.multisample_quality)
+ {
+ swapchain->desc.multisample_type = multisample_type;
+ swapchain->desc.multisample_quality = multisample_quality;
+ update_desc = TRUE;
+ }
+
+ if (update_desc)
+ {
+ HRESULT hr;
+ UINT i;
+
+ if (FAILED(hr = wined3d_texture_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
+ swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
+ swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
+ return hr;
+
+ for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
+ {
+ if (FAILED(hr = wined3d_texture_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
+ swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
+ swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
+ return hr;
+ }
+ }
+
+ swapchain_update_render_to_fbo(swapchain);
+ swapchain_update_draw_bindings(swapchain);
+
+ return WINED3D_OK;
+}
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index c22fe33..17a0a4c 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2812,8 +2812,10 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa
struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
HDC swapchain_get_backup_dc(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
+HRESULT wined3d_swapchain_resize_buffers(struct wined3d_swapchain *swapchain, unsigned int buffer_count,
+ unsigned int width, unsigned int height, enum wined3d_format_id format_id,
+ enum wined3d_multisample_type multisample_type, unsigned int multisample_quality) DECLSPEC_HIDDEN;
void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
-void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
/*****************************************************************************
* Utility function prototypes
--
2.1.4
More information about the wine-patches
mailing list