wined3d: Determine output from window position in wined3d_hook_proc().

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-12 20:49:55 +08:00 committed by Alexandre Julliard
parent d3e088cc00
commit e79d577be8
1 changed files with 37 additions and 2 deletions

View File

@ -459,6 +459,39 @@ static void wined3d_wndproc_mutex_unlock(void)
LeaveCriticalSection(&wined3d_wndproc_cs);
}
static 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_DEFAULTTONEAREST);
monitor_info.cbSize = sizeof(monitor_info);
if (!GetMonitorInfoW(monitor, (MONITORINFO *)&monitor_info))
{
ERR("GetMonitorInfoW failed, error %#x.\n", GetLastError());
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];
}
}
/* Because wined3d only supports one output right now. A window can be on non-primary outputs
* and thus fails to get its correct output. In this case, return the primary output for now */
return &wined3d->adapters[0]->outputs[0];
}
static struct wined3d_wndproc *wined3d_find_wndproc(HWND window, struct wined3d *wined3d)
{
unsigned int i;
@ -565,11 +598,13 @@ 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;
if (!(output = wined3d_swapchain_get_output(swapchain)))
if (!(output = wined3d_get_output_from_window(swapchain->device->wined3d,
swapchain->state.device_window)))
{
ERR("Failed to get output from swapchain %p.\n", swapchain);
ERR("Failed to get output from window %p.\n", swapchain->state.device_window);
break;
}
swapchain_desc.output = output;
wined3d_swapchain_state_set_fullscreen(&swapchain->state, &swapchain_desc, output,
NULL);