From bd10362667f04d6ea82144d1871ce143549a6bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 25 Aug 2016 12:22:56 +0200 Subject: [PATCH] wined3d: Optionally use closest matching mode in wined3d_swapchain_resize_target(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/dxgi/tests/device.c | 5 ++-- dlls/wined3d/swapchain.c | 60 +++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/dlls/dxgi/tests/device.c b/dlls/dxgi/tests/device.c index 41a4d859331..d9cedff0d87 100644 --- a/dlls/dxgi/tests/device.c +++ b/dlls/dxgi/tests/device.c @@ -2215,10 +2215,9 @@ static void test_inexact_modes(void) swapchain_desc.BufferDesc.Width = sizes[i].width; swapchain_desc.BufferDesc.Height = sizes[i].height; hr = IDXGISwapChain_ResizeTarget(swapchain, &swapchain_desc.BufferDesc); - todo_wine ok(SUCCEEDED(hr), "ResizeTarget failed, hr %#x.\n", hr); + ok(SUCCEEDED(hr), "ResizeTarget failed, hr %#x.\n", hr); - if (SUCCEEDED(hr)) - check_swapchain_fullscreen_state(swapchain, &expected_state); + check_swapchain_fullscreen_state(swapchain, &expected_state); hr = IDXGISwapChain_GetDesc(swapchain, &result_desc); ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr); ok(result_desc.BufferDesc.Width == 800, "Got width %u.\n", result_desc.BufferDesc.Width); diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c index fdfe337d2c3..695d40988a4 100644 --- a/dlls/wined3d/swapchain.c +++ b/dlls/wined3d/swapchain.c @@ -1397,20 +1397,44 @@ HRESULT CDECL wined3d_swapchain_resize_buffers(struct wined3d_swapchain *swapcha return WINED3D_OK; } +static HRESULT wined3d_swapchain_set_display_mode(struct wined3d_swapchain *swapchain, + struct wined3d_display_mode *mode) +{ + struct wined3d_device *device = swapchain->device; + HRESULT hr; + + if (swapchain->desc.flags & WINED3D_SWAPCHAIN_USE_CLOSEST_MATCHING_MODE) + { + if (FAILED(hr = wined3d_find_closest_matching_adapter_mode(device->wined3d, + device->adapter->ordinal, mode))) + { + WARN("Failed to find closest matching mode, hr %#x.\n", hr); + } + } + + if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, + device->adapter->ordinal, mode))) + { + WARN("Failed to set display mode, hr %#x.\n", hr); + return WINED3DERR_INVALIDCALL; + } + + return WINED3D_OK; +} + HRESULT CDECL wined3d_swapchain_resize_target(struct wined3d_swapchain *swapchain, const struct wined3d_display_mode *mode) { struct wined3d_device *device = swapchain->device; - struct wined3d_display_mode current_mode; + struct wined3d_display_mode actual_mode; RECT original_window_rect, window_rect; HRESULT hr; TRACE("swapchain %p, mode %p.\n", swapchain, mode); - SetRect(&window_rect, 0, 0, mode->width, mode->height); - if (swapchain->desc.windowed) { + SetRect(&window_rect, 0, 0, mode->width, mode->height); AdjustWindowRectEx(&window_rect, GetWindowLongW(swapchain->device_window, GWL_STYLE), FALSE, GetWindowLongW(swapchain->device_window, GWL_EXSTYLE)); @@ -1421,22 +1445,21 @@ HRESULT CDECL wined3d_swapchain_resize_target(struct wined3d_swapchain *swapchai } else if (swapchain->desc.flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH) { - if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, mode))) - { - WARN("Failed to set display mode, hr %#x.\n", hr); - return WINED3DERR_INVALIDCALL; - } + actual_mode = *mode; + if (FAILED(hr = wined3d_swapchain_set_display_mode(swapchain, &actual_mode))) + return hr; + SetRect(&window_rect, 0, 0, actual_mode.width, actual_mode.height); } else { if (FAILED(hr = wined3d_get_adapter_display_mode(device->wined3d, device->adapter->ordinal, - ¤t_mode, NULL))) + &actual_mode, NULL))) { ERR("Failed to get display mode, hr %#x.\n", hr); return WINED3DERR_INVALIDCALL; } - SetRect(&window_rect, 0, 0, current_mode.width, current_mode.height); + SetRect(&window_rect, 0, 0, actual_mode.width, actual_mode.height); } MoveWindow(swapchain->device_window, window_rect.left, window_rect.top, @@ -1477,21 +1500,8 @@ HRESULT CDECL wined3d_swapchain_set_fullscreen(struct wined3d_swapchain *swapcha } } - if (swapchain->desc.flags & WINED3D_SWAPCHAIN_USE_CLOSEST_MATCHING_MODE) - { - if (FAILED(hr = wined3d_find_closest_matching_adapter_mode(device->wined3d, - device->adapter->ordinal, &actual_mode))) - { - WARN("Failed to find closest matching mode, hr %#x.\n", hr); - } - } - - if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, - device->adapter->ordinal, &actual_mode))) - { - WARN("Failed to set display mode, hr %#x.\n", hr); - return WINED3DERR_INVALIDCALL; - } + if (FAILED(hr = wined3d_swapchain_set_display_mode(swapchain, &actual_mode))) + return hr; } else {