wined3d: Get output from swapchain state.

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:50:12 +08:00 committed by Alexandre Julliard
parent e79d577be8
commit f6d2e03750
4 changed files with 12 additions and 59 deletions

View file

@ -2924,7 +2924,6 @@ static HRESULT d3d12_swapchain_init(struct d3d12_swapchain *swapchain, IWineDXGI
struct wined3d_swapchain_desc wined3d_desc;
VkWin32SurfaceCreateInfoKHR surface_desc;
VkPhysicalDevice vk_physical_device;
struct dxgi_adapter *dxgi_adapter;
VkFenceCreateInfo fence_desc;
uint32_t queue_family_index;
VkSurfaceKHR vk_surface;
@ -2973,7 +2972,6 @@ static HRESULT d3d12_swapchain_init(struct d3d12_swapchain *swapchain, IWineDXGI
device_parent = vkd3d_get_device_parent(device);
if (FAILED(hr = IUnknown_QueryInterface(device_parent, &IID_IDXGIAdapter, (void **)&adapter)))
return hr;
dxgi_adapter = unsafe_impl_from_IDXGIAdapter(adapter);
if (FAILED(hr = dxgi_get_output_from_window((IDXGIFactory *)factory, window, &output)))
{
@ -2998,8 +2996,7 @@ static HRESULT d3d12_swapchain_init(struct d3d12_swapchain *swapchain, IWineDXGI
IDXGIOutput_Release(output);
if (FAILED(hr))
return hr;
if (FAILED(hr = wined3d_swapchain_state_create(&wined3d_desc, window,
dxgi_adapter->factory->wined3d, &swapchain->state)))
if (FAILED(hr = wined3d_swapchain_state_create(&wined3d_desc, window, &swapchain->state)))
return hr;
if (swapchain_desc->BufferUsage && swapchain_desc->BufferUsage != DXGI_USAGE_RENDER_TARGET_OUTPUT)

View file

@ -259,49 +259,11 @@ struct wined3d_texture * CDECL wined3d_swapchain_get_back_buffer(const struct wi
return swapchain->back_buffers[back_buffer_idx];
}
static struct wined3d_output * 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))
{
ERR("Failed to get monitor information.\n");
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];
}
struct wined3d_output * wined3d_swapchain_get_output(const struct wined3d_swapchain *swapchain)
{
HWND hwnd;
TRACE("swapchain %p.\n", swapchain);
hwnd = swapchain->state.device_window;
if (!hwnd)
hwnd = swapchain->win_handle;
return get_output_from_window(swapchain->device->wined3d, hwnd);
return swapchain->state.desc.output;
}
HRESULT CDECL wined3d_swapchain_get_raster_status(const struct wined3d_swapchain *swapchain,
@ -825,20 +787,13 @@ static enum wined3d_format_id adapter_format_from_backbuffer_format(const struct
}
static HRESULT wined3d_swapchain_state_init(struct wined3d_swapchain_state *state,
const struct wined3d_swapchain_desc *desc, HWND window, struct wined3d *wined3d)
const struct wined3d_swapchain_desc *desc, HWND window)
{
struct wined3d_output *output;
HRESULT hr;
state->desc = *desc;
if (!(output = get_output_from_window(wined3d, window)))
{
WARN("Failed to get output from window %p.\n", window);
return E_FAIL;
}
if (FAILED(hr = wined3d_output_get_display_mode(output, &state->original_mode, NULL)))
if (FAILED(hr = wined3d_output_get_display_mode(desc->output, &state->original_mode, NULL)))
{
ERR("Failed to get current display mode, hr %#x.\n", hr);
return hr;
@ -850,7 +805,7 @@ static HRESULT wined3d_swapchain_state_init(struct wined3d_swapchain_state *stat
{
state->d3d_mode.width = desc->backbuffer_width;
state->d3d_mode.height = desc->backbuffer_height;
state->d3d_mode.format_id = adapter_format_from_backbuffer_format(output->adapter,
state->d3d_mode.format_id = adapter_format_from_backbuffer_format(desc->output->adapter,
desc->backbuffer_format);
state->d3d_mode.refresh_rate = desc->refresh_rate;
state->d3d_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
@ -894,7 +849,7 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
FIXME("Unimplemented swap effect %#x.\n", desc->swap_effect);
window = desc->device_window ? desc->device_window : device->create_parms.focus_window;
if (FAILED(hr = wined3d_swapchain_state_init(&swapchain->state, desc, window, device->wined3d)))
if (FAILED(hr = wined3d_swapchain_state_init(&swapchain->state, desc, window)))
{
ERR("Failed to initialise swapchain state, hr %#x.\n", hr);
goto err;
@ -1739,6 +1694,7 @@ HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_st
wined3d_swapchain_state_restore_from_fullscreen(state, state->device_window, window_rect);
}
state->desc.output = output;
state->desc.windowed = swapchain_desc->windowed;
return WINED3D_OK;
@ -1750,17 +1706,17 @@ void CDECL wined3d_swapchain_state_destroy(struct wined3d_swapchain_state *state
}
HRESULT CDECL wined3d_swapchain_state_create(const struct wined3d_swapchain_desc *desc,
HWND window, struct wined3d *wined3d, struct wined3d_swapchain_state **state)
HWND window, struct wined3d_swapchain_state **state)
{
struct wined3d_swapchain_state *s;
HRESULT hr;
TRACE("desc %p, window %p, wined3d %p, state %p.\n", desc, window, wined3d, state);
TRACE("desc %p, window %p, state %p.\n", desc, window, state);
if (!(s = heap_alloc_zero(sizeof(*s))))
return E_OUTOFMEMORY;
if (FAILED(hr = wined3d_swapchain_state_init(s, desc, window, wined3d)))
if (FAILED(hr = wined3d_swapchain_state_init(s, desc, window)))
{
heap_free(s);
return hr;

View file

@ -281,7 +281,7 @@
@ cdecl wined3d_swapchain_set_palette(ptr ptr)
@ cdecl wined3d_swapchain_set_window(ptr ptr)
@ cdecl wined3d_swapchain_state_create(ptr ptr ptr ptr)
@ cdecl wined3d_swapchain_state_create(ptr ptr ptr)
@ cdecl wined3d_swapchain_state_destroy(ptr)
@ cdecl wined3d_swapchain_state_resize_target(ptr ptr ptr)
@ cdecl wined3d_swapchain_state_set_fullscreen(ptr ptr ptr ptr)

View file

@ -2769,7 +2769,7 @@ void __cdecl wined3d_swapchain_set_palette(struct wined3d_swapchain *swapchain,
void __cdecl wined3d_swapchain_set_window(struct wined3d_swapchain *swapchain, HWND window);
HRESULT __cdecl wined3d_swapchain_state_create(const struct wined3d_swapchain_desc *desc,
HWND window, struct wined3d *wined3d, struct wined3d_swapchain_state **state);
HWND window, 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_output *output, const struct wined3d_display_mode *mode);