Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/dxgi/swapchain.c | 2 +- dlls/wined3d/device.c | 11 ++++++++++- dlls/wined3d/directx.c | 27 +++++++++++++++++++++++++++ dlls/wined3d/swapchain.c | 14 ++++++-------- dlls/wined3d/wined3d.spec | 2 +- dlls/wined3d/wined3d_main.c | 10 +++++++++- dlls/wined3d/wined3d_private.h | 3 +++ include/wine/wined3d.h | 2 +- 8 files changed, 58 insertions(+), 13 deletions(-)
diff --git a/dlls/dxgi/swapchain.c b/dlls/dxgi/swapchain.c index 004bd1457dd..603cf171e27 100644 --- a/dlls/dxgi/swapchain.c +++ b/dlls/dxgi/swapchain.c @@ -164,7 +164,7 @@ static HRESULT dxgi_swapchain_set_fullscreen_state(struct wined3d_swapchain_stat
wined3d_mutex_lock(); hr = wined3d_swapchain_state_set_fullscreen(state, swapchain_desc, - adapter->factory->wined3d, adapter->ordinal, NULL); + adapter->factory->wined3d, dxgi_output->wined3d_output, NULL); wined3d_mutex_unlock();
return hr; diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 99fbf21ada2..c338307564b 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -5347,6 +5347,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, struct wined3d_swapchain *swapchain; struct wined3d_view_desc view_desc; BOOL backbuffer_resized, windowed; + struct wined3d_output *output; HRESULT hr = WINED3D_OK; unsigned int i;
@@ -5455,8 +5456,16 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device, return hr; } } + + output = wined3d_get_output_from_window(device->wined3d, swapchain->state.device_window); + if (!output) + { + ERR("Failed to get output from window %p.\n", swapchain->state.device_window); + return E_FAIL; + } + if (FAILED(hr = wined3d_swapchain_state_set_fullscreen(&swapchain->state, - swapchain_desc, device->wined3d, device->adapter->ordinal, mode))) + swapchain_desc, device->wined3d, output, mode))) return hr;
/* Switch from fullscreen to windowed. */ diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 614a6eea8d7..06f337d3648 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -146,6 +146,33 @@ static HRESULT wined3d_output_init(struct wined3d_output *output, struct wined3d return WINED3D_OK; }
+struct wined3d_output * wined3d_get_output_from_window(const struct wined3d *wined3d, HWND hwnd) +{ + unsigned int adapter_idx, output_idx; + struct wined3d_adapter *adapter; + MONITORINFOEXW monitor_info; + HMONITOR monitor; + + TRACE("wined3d %p, hwnd %p.\n", wined3d, hwnd); + + monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); + monitor_info.cbSize = sizeof(monitor_info); + if (!GetMonitorInfoW(monitor, (MONITORINFO *)&monitor_info)) + return NULL; + + for (adapter_idx = 0; adapter_idx < wined3d->adapter_count; ++adapter_idx) + { + adapter = wined3d->adapters[adapter_idx]; + for (output_idx = 0; output_idx < adapter->output_count; ++output_idx) + { + if (!lstrcmpiW(adapter->outputs[output_idx].device_name, monitor_info.szDevice)) + return &adapter->outputs[output_idx]; + } + } + + return NULL; +} + /* Adjust the amount of used texture memory */ UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount) { diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c index 62bab65fcf3..12d172b0e06 100644 --- a/dlls/wined3d/swapchain.c +++ b/dlls/wined3d/swapchain.c @@ -1566,13 +1566,13 @@ void wined3d_swapchain_state_restore_from_fullscreen(struct wined3d_swapchain_st
HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_state *state, const struct wined3d_swapchain_desc *swapchain_desc, struct wined3d *wined3d, - unsigned int adapter_idx, const struct wined3d_display_mode *mode) + struct wined3d_output *output, const struct wined3d_display_mode *mode) { struct wined3d_display_mode actual_mode; HRESULT hr;
- TRACE("state %p, swapchain_desc %p, wined3d %p, adapter_idx %u, mode %p.\n", - state, swapchain_desc, wined3d, adapter_idx, mode); + TRACE("state %p, swapchain_desc %p, wined3d %p, output %p, mode %p.\n", + state, swapchain_desc, wined3d, output, mode);
if (state->desc.flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH) { @@ -1584,12 +1584,10 @@ HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_st { if (!swapchain_desc->windowed) { - const struct wined3d_adapter *adapter = wined3d->adapters[adapter_idx]; - actual_mode.width = swapchain_desc->backbuffer_width; actual_mode.height = swapchain_desc->backbuffer_height; actual_mode.refresh_rate = swapchain_desc->refresh_rate; - actual_mode.format_id = adapter_format_from_backbuffer_format(adapter, + actual_mode.format_id = adapter_format_from_backbuffer_format(output->adapter, swapchain_desc->backbuffer_format); actual_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN; } @@ -1599,7 +1597,7 @@ HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_st } }
- if (FAILED(hr = wined3d_swapchain_state_set_display_mode(state, wined3d, adapter_idx, &actual_mode))) + if (FAILED(hr = wined3d_swapchain_state_set_display_mode(state, wined3d, 0, &actual_mode))) return hr; } else @@ -1607,7 +1605,7 @@ HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_st if (mode) WARN("WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH is not set, ignoring mode.\n");
- if (FAILED(hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &actual_mode, NULL))) + if (FAILED(hr = wined3d_get_adapter_display_mode(wined3d, 0, &actual_mode, NULL))) { ERR("Failed to get display mode, hr %#x.\n", hr); return WINED3DERR_INVALIDCALL; diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index ca626638338..bb82a6121a4 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -315,7 +315,7 @@ @ 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_set_fullscreen(ptr ptr ptr ptr ptr)
@ 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_main.c b/dlls/wined3d/wined3d_main.c index 05684aeb3ba..21f664d7de7 100644 --- a/dlls/wined3d/wined3d_main.c +++ b/dlls/wined3d/wined3d_main.c @@ -540,6 +540,7 @@ static LRESULT CALLBACK wined3d_hook_proc(int code, WPARAM wparam, LPARAM lparam { struct wined3d_swapchain_desc swapchain_desc; struct wined3d_swapchain *swapchain; + struct wined3d_output *output; struct wined3d_wndproc *entry; MSG *msg = (MSG *)lparam; unsigned int i; @@ -564,8 +565,15 @@ static LRESULT CALLBACK wined3d_hook_proc(int code, WPARAM wparam, LPARAM lparam
wined3d_swapchain_get_desc(swapchain, &swapchain_desc); swapchain_desc.windowed = !swapchain_desc.windowed; + output = wined3d_get_output_from_window(swapchain->device->wined3d, + swapchain->state.device_window); + if (!output) + { + ERR("Failed to get output from window %p.\n", swapchain->state.device_window); + break; + } wined3d_swapchain_state_set_fullscreen(&swapchain->state, &swapchain_desc, - swapchain->device->wined3d, swapchain->device->adapter->ordinal, NULL); + swapchain->device->wined3d, output, NULL);
wined3d_wndproc_mutex_unlock();
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 4c7ea1f1628..30a07b4a5ea 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -2906,6 +2906,9 @@ struct wined3d_output D3DDDI_VIDEO_PRESENT_SOURCE_ID vidpn_source_id; };
+struct wined3d_output * wined3d_get_output_from_window(const struct wined3d *wined3d, + HWND hwnd) DECLSPEC_HIDDEN; + /* The adapter structure */ struct wined3d_adapter { diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 9600bf63ee7..edd350e11a4 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -2818,7 +2818,7 @@ HRESULT __cdecl wined3d_swapchain_state_resize_target(struct wined3d_swapchain_s struct wined3d *wined3d, unsigned int adapter_idx, const struct wined3d_display_mode *mode); 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); + struct wined3d_output *output, const struct wined3d_display_mode *mode);
HRESULT __cdecl wined3d_texture_add_dirty_region(struct wined3d_texture *texture, UINT layer, const struct wined3d_box *dirty_region);