wined3d: Move device window to the correct output when changing swapchain state to full screen.

Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zhiyi Zhang 2020-05-07 15:52:12 +08:00 committed by Alexandre Julliard
parent 094c344f27
commit e847b08229
3 changed files with 47 additions and 13 deletions

View File

@ -4954,6 +4954,12 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
|| swapchain_desc->backbuffer_height != current_desc->backbuffer_height;
windowed = current_desc->windowed;
if (!(output = wined3d_swapchain_get_output(swapchain)))
{
ERR("Failed to get output from swapchain %p.\n", swapchain);
return E_FAIL;
}
if (!swapchain_desc->windowed != !windowed || swapchain->reapply_mode
|| mode || (!swapchain_desc->windowed && backbuffer_resized))
{
@ -4971,11 +4977,6 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
}
}
if (!(output = wined3d_swapchain_get_output(swapchain)))
{
ERR("Failed to get output from swapchain %p.\n", swapchain);
return E_FAIL;
}
if (FAILED(hr = wined3d_swapchain_state_set_fullscreen(&swapchain->state,
swapchain_desc, output, mode)))
return hr;
@ -4988,13 +4989,22 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
{
DWORD style = swapchain_state->style;
DWORD exstyle = swapchain_state->exstyle;
struct wined3d_output_desc output_desc;
/* 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 clean
* up their mess. Guild Wars also loses the device during that. */
if (FAILED(hr = wined3d_output_get_desc(output, &output_desc)))
{
ERR("Failed to get output description, hr %#x.\n", hr);
return hr;
}
swapchain_state->style = 0;
swapchain_state->exstyle = 0;
wined3d_swapchain_state_setup_fullscreen(swapchain_state, swapchain_state->device_window,
output_desc.desktop_rect.left, output_desc.desktop_rect.top,
swapchain_desc->backbuffer_width, swapchain_desc->backbuffer_height);
swapchain_state->style = style;
swapchain_state->exstyle = exstyle;

View File

@ -872,13 +872,14 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
const struct wined3d_swapchain_ops *swapchain_ops)
{
struct wined3d_resource_desc texture_desc;
struct wined3d_output_desc output_desc;
struct wined3d_output *output;
BOOL displaymode_set = FALSE;
DWORD texture_flags = 0;
HRESULT hr = E_FAIL;
RECT client_rect;
unsigned int i;
HWND window;
HRESULT hr;
wined3d_mutex_lock();
@ -933,8 +934,21 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
}
else
{
wined3d_swapchain_state_setup_fullscreen(&swapchain->state,
window, desc->backbuffer_width, desc->backbuffer_height);
if (!(output = wined3d_swapchain_get_output(swapchain)))
{
ERR("Failed to get output from swapchain %p.\n", swapchain);
goto err;
}
if (FAILED(hr = wined3d_output_get_desc(output, &output_desc)))
{
ERR("Failed to get output description, hr %#x.\n", hr);
goto err;
}
wined3d_swapchain_state_setup_fullscreen(&swapchain->state, window,
output_desc.desktop_rect.left, output_desc.desktop_rect.top, desc->backbuffer_width,
desc->backbuffer_height);
}
swapchain->state.desc = *desc;
wined3d_swapchain_apply_sample_count_override(swapchain, swapchain->state.desc.backbuffer_format,
@ -1551,7 +1565,7 @@ static LONG fullscreen_exstyle(LONG exstyle)
}
HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state,
HWND window, unsigned int w, unsigned int h)
HWND window, int x, int y, int width, int height)
{
LONG style, exstyle;
BOOL filter;
@ -1583,7 +1597,8 @@ HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state
SetWindowLongW(window, GWL_STYLE, style);
SetWindowLongW(window, GWL_EXSTYLE, exstyle);
SetWindowPos(window, HWND_TOPMOST, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
SetWindowPos(window, HWND_TOPMOST, x, y, width, height,
SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
wined3d_filter_messages(window, filter);
@ -1647,6 +1662,7 @@ HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_st
const struct wined3d_display_mode *mode)
{
struct wined3d_display_mode actual_mode;
struct wined3d_output_desc output_desc;
HRESULT hr;
TRACE("state %p, swapchain_desc %p, output %p, mode %p.\n",
@ -1695,10 +1711,17 @@ HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_st
unsigned int width = actual_mode.width;
unsigned int height = actual_mode.height;
if (FAILED(hr = wined3d_output_get_desc(output, &output_desc)))
{
ERR("Failed to get output description, hr %#x.\n", hr);
return hr;
}
if (state->desc.windowed)
{
/* Switch from windowed to fullscreen */
if (FAILED(hr = wined3d_swapchain_state_setup_fullscreen(state, state->device_window, width, height)))
if (FAILED(hr = wined3d_swapchain_state_setup_fullscreen(state, state->device_window,
output_desc.desktop_rect.left, output_desc.desktop_rect.top, width, height)))
return hr;
}
else
@ -1708,7 +1731,8 @@ HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_st
/* Fullscreen -> fullscreen mode change */
filter = wined3d_filter_messages(window, TRUE);
MoveWindow(window, 0, 0, width, height, TRUE);
MoveWindow(window, output_desc.desktop_rect.left, output_desc.desktop_rect.top, width,
height, TRUE);
ShowWindow(window, SW_SHOW);
wined3d_filter_messages(window, filter);
}

View File

@ -4720,7 +4720,7 @@ 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;
HWND window, int x, int y, int width, int height) DECLSPEC_HIDDEN;
struct wined3d_swapchain_ops
{