Commit 7161e01a authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

wined3d: Refactor wined3d_set_adapter_display_mode() to wined3d_output_set_display_mode().

parent 3635e09d
......@@ -683,7 +683,7 @@ static HRESULT WINAPI ddraw7_RestoreDisplayMode(IDirectDraw7 *iface)
return DDERR_NOEXCLUSIVEMODE;
}
if (SUCCEEDED(hr = wined3d_set_adapter_display_mode(ddraw->wined3d, WINED3DADAPTER_DEFAULT, NULL)))
if (SUCCEEDED(hr = wined3d_output_set_display_mode(ddraw->wined3d_output, NULL)))
ddraw->flags &= ~DDRAW_RESTORE_MODE;
InterlockedCompareExchange(&ddraw->device_state, DDRAW_DEVICE_STATE_NOT_RESTORED, DDRAW_DEVICE_STATE_OK);
......@@ -1104,7 +1104,7 @@ static HRESULT WINAPI ddraw7_SetDisplayMode(IDirectDraw7 *iface, DWORD width, DW
/* TODO: The possible return values from msdn suggest that the screen mode
* can't be changed if a surface is locked or some drawing is in progress. */
if (SUCCEEDED(hr = wined3d_set_adapter_display_mode(ddraw->wined3d, WINED3DADAPTER_DEFAULT, &mode)))
if (SUCCEEDED(hr = wined3d_output_set_display_mode(ddraw->wined3d_output, &mode)))
{
if (ddraw->primary)
{
......
......@@ -1209,12 +1209,12 @@ HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UI
* are pretty angry if they SetDisplayMode from 24 to 16 bpp and find out
* that GetDisplayMode still returns 24 bpp. This should probably be
* handled in winex11 instead. */
if (adapter->screen_format && adapter->screen_format != mode->format_id)
if (adapter->outputs[0].screen_format && adapter->outputs[0].screen_format != mode->format_id)
{
WARN("Overriding format %s with stored format %s.\n",
debug_d3dformat(mode->format_id),
debug_d3dformat(adapter->screen_format));
mode->format_id = adapter->screen_format;
debug_d3dformat(adapter->outputs[0].screen_format));
mode->format_id = adapter->outputs[0].screen_format;
}
if (!(m.dmFields & DM_DISPLAYFLAGS))
......@@ -1253,20 +1253,15 @@ HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UI
return WINED3D_OK;
}
HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
UINT adapter_idx, const struct wined3d_display_mode *mode)
HRESULT CDECL wined3d_output_set_display_mode(struct wined3d_output *output,
const struct wined3d_display_mode *mode)
{
struct wined3d_adapter *adapter;
DEVMODEW new_mode, current_mode;
RECT clip_rc;
LONG ret;
enum wined3d_format_id new_format_id;
TRACE("wined3d %p, adapter_idx %u, mode %p.\n", wined3d, adapter_idx, mode);
if (adapter_idx >= wined3d->adapter_count)
return WINED3DERR_INVALIDCALL;
adapter = wined3d->adapters[adapter_idx];
TRACE("output %p, mode %p.\n", output, mode);
memset(&new_mode, 0, sizeof(new_mode));
new_mode.dmSize = sizeof(new_mode);
......@@ -1279,7 +1274,7 @@ HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
TRACE("mode %ux%u@%u %s %#x.\n", mode->width, mode->height, mode->refresh_rate,
debug_d3dformat(mode->format_id), mode->scanline_ordering);
format = wined3d_get_format(adapter, mode->format_id, WINED3D_BIND_RENDER_TARGET);
format = wined3d_get_format(output->adapter, mode->format_id, WINED3D_BIND_RENDER_TARGET);
new_mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
new_mode.dmBitsPerPel = format->byte_count * CHAR_BIT;
......@@ -1300,7 +1295,7 @@ HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
}
else
{
if (!EnumDisplaySettingsW(adapter->device_name, ENUM_REGISTRY_SETTINGS, &new_mode))
if (!EnumDisplaySettingsW(output->device_name, ENUM_REGISTRY_SETTINGS, &new_mode))
{
ERR("Failed to read mode from registry.\n");
return WINED3DERR_NOTAVAILABLE;
......@@ -1309,7 +1304,7 @@ HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
}
/* Only change the mode if necessary. */
if (!EnumDisplaySettingsW(adapter->device_name, ENUM_CURRENT_SETTINGS, &current_mode))
if (!EnumDisplaySettingsW(output->device_name, ENUM_CURRENT_SETTINGS, &current_mode))
{
ERR("Failed to get current display mode.\n");
}
......@@ -1322,11 +1317,11 @@ HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
|| !(new_mode.dmFields & DM_DISPLAYFLAGS)))
{
TRACE("Skipping redundant mode setting call.\n");
adapter->screen_format = new_format_id;
output->screen_format = new_format_id;
return WINED3D_OK;
}
ret = ChangeDisplaySettingsExW(adapter->device_name, &new_mode, NULL, CDS_FULLSCREEN, NULL);
ret = ChangeDisplaySettingsExW(output->device_name, &new_mode, NULL, CDS_FULLSCREEN, NULL);
if (ret != DISP_CHANGE_SUCCESSFUL)
{
if (new_mode.dmFields & DM_DISPLAYFREQUENCY)
......@@ -1334,14 +1329,14 @@ HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
WARN("ChangeDisplaySettingsExW failed, trying without the refresh rate.\n");
new_mode.dmFields &= ~DM_DISPLAYFREQUENCY;
new_mode.dmDisplayFrequency = 0;
ret = ChangeDisplaySettingsExW(adapter->device_name, &new_mode, NULL, CDS_FULLSCREEN, NULL);
ret = ChangeDisplaySettingsExW(output->device_name, &new_mode, NULL, CDS_FULLSCREEN, NULL);
}
if (ret != DISP_CHANGE_SUCCESSFUL)
return WINED3DERR_NOTAVAILABLE;
}
/* Store the new values. */
adapter->screen_format = new_format_id;
output->screen_format = new_format_id;
/* And finally clip mouse to our screen. */
SetRect(&clip_rc, 0, 0, new_mode.dmPelsWidth, new_mode.dmPelsHeight);
......
......@@ -29,7 +29,8 @@ WINE_DECLARE_DEBUG_CHANNEL(fps);
void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain)
{
HRESULT hr;
struct wined3d_output *output;
HRESULT hr = E_FAIL;
UINT i;
TRACE("Destroying swapchain %p.\n", swapchain);
......@@ -71,8 +72,9 @@ void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain)
{
if (swapchain->state.desc.auto_restore_display_mode)
{
if (FAILED(hr = wined3d_set_adapter_display_mode(swapchain->device->wined3d,
swapchain->device->adapter->ordinal, &swapchain->state.original_mode)))
output = wined3d_swapchain_get_output(swapchain);
if (!output || FAILED(hr = wined3d_output_set_display_mode(output,
&swapchain->state.original_mode)))
ERR("Failed to restore display mode, hr %#x.\n", hr);
if (swapchain->state.desc.flags & WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
......@@ -858,6 +860,7 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
{
const struct wined3d_adapter *adapter = device->adapter;
struct wined3d_resource_desc texture_desc;
struct wined3d_output *output;
BOOL displaymode_set = FALSE;
DWORD texture_flags = 0;
RECT client_rect;
......@@ -964,8 +967,9 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
if (!desc->windowed && desc->flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
{
/* Change the display settings */
if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d,
adapter->ordinal, &swapchain->state.d3d_mode)))
output = wined3d_swapchain_get_output(swapchain);
if (!output || FAILED(hr = wined3d_output_set_display_mode(output,
&swapchain->state.d3d_mode)))
{
WARN("Failed to set display mode, hr %#x.\n", hr);
goto err;
......@@ -1048,8 +1052,8 @@ static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struc
err:
if (displaymode_set)
{
if (FAILED(wined3d_set_adapter_display_mode(device->wined3d,
adapter->ordinal, &swapchain->state.original_mode)))
if (!output || FAILED(wined3d_output_set_display_mode(output,
&swapchain->state.original_mode)))
ERR("Failed to restore display mode.\n");
ClipCursor(NULL);
}
......@@ -1261,6 +1265,7 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa
struct wined3d_device *device = swapchain->device;
HWND window = swapchain->state.device_window;
unsigned int screensaver_active;
struct wined3d_output *output;
BOOL focus_messages, filter;
/* This code is not protected by the wined3d mutex, so it may run while
......@@ -1292,8 +1297,9 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa
if (device->wined3d->flags & WINED3D_RESTORE_MODE_ON_ACTIVATE)
{
if (FAILED(wined3d_set_adapter_display_mode(device->wined3d,
device->adapter->ordinal, &swapchain->state.d3d_mode)))
output = wined3d_swapchain_get_output(swapchain);
if (!output || FAILED(wined3d_output_set_display_mode(output,
&swapchain->state.d3d_mode)))
ERR("Failed to set display mode.\n");
}
......@@ -1308,8 +1314,8 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa
device->restore_screensaver = FALSE;
}
if (FAILED(wined3d_set_adapter_display_mode(device->wined3d,
device->adapter->ordinal, NULL)))
output = wined3d_swapchain_get_output(swapchain);
if (!output || FAILED(wined3d_output_set_display_mode(output, NULL)))
ERR("Failed to set display mode.\n");
swapchain->reapply_mode = TRUE;
......@@ -1442,7 +1448,7 @@ static HRESULT wined3d_swapchain_state_set_display_mode(struct wined3d_swapchain
}
}
if (FAILED(hr = wined3d_set_adapter_display_mode(wined3d, 0, mode)))
if (FAILED(hr = wined3d_output_set_display_mode(output, mode)))
{
WARN("Failed to set display mode, hr %#x.\n", hr);
return WINED3DERR_INVALIDCALL;
......
......@@ -20,7 +20,6 @@
@ cdecl wined3d_incref(ptr)
@ cdecl wined3d_register_software_device(ptr ptr)
@ cdecl wined3d_register_window(ptr ptr ptr long)
@ cdecl wined3d_set_adapter_display_mode(ptr long ptr)
@ cdecl wined3d_unregister_windows(ptr)
@ cdecl wined3d_adapter_get_output(ptr long)
......@@ -162,6 +161,7 @@
@ cdecl wined3d_output_get_mode(ptr long long long ptr)
@ cdecl wined3d_output_get_mode_count(ptr long long)
@ cdecl wined3d_output_set_display_mode(ptr ptr)
@ cdecl wined3d_output_release_ownership(ptr)
@ cdecl wined3d_output_take_ownership(ptr long)
......
......@@ -2900,6 +2900,7 @@ struct wined3d_output
{
WCHAR device_name[CCHDEVICENAME];
struct wined3d_adapter *adapter;
enum wined3d_format_id screen_format;
D3DKMT_HANDLE kmt_adapter;
D3DKMT_HANDLE kmt_device;
......@@ -2911,7 +2912,6 @@ struct wined3d_adapter
{
unsigned int ordinal;
POINT monitor_position;
enum wined3d_format_id screen_format;
struct wined3d_gl_info gl_info;
struct wined3d_d3d_info d3d_info;
......
......@@ -2280,8 +2280,6 @@ ULONG __cdecl wined3d_incref(struct wined3d *wined3d);
HRESULT __cdecl wined3d_register_software_device(struct wined3d *wined3d, void *init_function);
BOOL __cdecl wined3d_register_window(struct wined3d *wined3d, HWND window,
struct wined3d_device *device, unsigned int flags);
HRESULT __cdecl wined3d_set_adapter_display_mode(struct wined3d *wined3d,
UINT adapter_idx, const struct wined3d_display_mode *mode);
void __cdecl wined3d_unregister_windows(struct wined3d *wined3d);
struct wined3d_output * __cdecl wined3d_adapter_get_output(const struct wined3d_adapter *adapter,
......@@ -2505,6 +2503,8 @@ HRESULT __cdecl wined3d_output_get_mode(const struct wined3d_output *output,
unsigned int __cdecl wined3d_output_get_mode_count(const struct wined3d_output *output,
enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering);
void __cdecl wined3d_output_release_ownership(const struct wined3d_output *output);
HRESULT __cdecl wined3d_output_set_display_mode(struct wined3d_output *output,
const struct wined3d_display_mode *mode);
HRESULT __cdecl wined3d_output_take_ownership(const struct wined3d_output *output, BOOL exclusive);
HRESULT __cdecl wined3d_palette_create(struct wined3d_device *device, DWORD flags,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment