2005-06-23 13:05:24 +02:00
|
|
|
/*
|
2011-04-07 18:45:58 +02:00
|
|
|
* Copyright 2002-2003 Jason Edmeades
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
|
|
|
* Copyright 2005 Oliver Stieber
|
|
|
|
* Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2011-04-13 19:14:31 +02:00
|
|
|
* Copyright 2011 Henri Verbeet for CodeWeavers
|
2005-06-23 13:05:24 +02:00
|
|
|
*
|
2011-04-07 18:45:58 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2005-06-23 13:05:24 +02:00
|
|
|
*
|
2011-04-07 18:45:58 +02:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2005-06-23 13:05:24 +02:00
|
|
|
*
|
2011-04-07 18:45:58 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-23 13:05:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-06-01 16:56:21 +02:00
|
|
|
#include "wine/port.h"
|
2005-06-23 13:05:24 +02:00
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
2011-04-07 18:45:59 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain)
|
2011-04-07 18:46:00 +02:00
|
|
|
{
|
2020-11-02 10:44:57 +01:00
|
|
|
HRESULT hr;
|
2011-04-07 18:46:00 +02:00
|
|
|
UINT i;
|
|
|
|
|
2011-04-12 18:28:40 +02:00
|
|
|
TRACE("Destroying swapchain %p.\n", swapchain);
|
2011-04-07 18:46:00 +02:00
|
|
|
|
2020-10-12 10:41:01 +02:00
|
|
|
wined3d_swapchain_state_cleanup(&swapchain->state);
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_set_gamma_ramp(swapchain, 0, &swapchain->orig_gamma);
|
2011-04-07 18:46:00 +02:00
|
|
|
|
|
|
|
/* Release the swapchain's draw buffers. Make sure swapchain->back_buffers[0]
|
|
|
|
* is the last buffer to be destroyed, FindContext() depends on that. */
|
|
|
|
if (swapchain->front_buffer)
|
|
|
|
{
|
2014-08-20 13:20:02 +02:00
|
|
|
wined3d_texture_set_swapchain(swapchain->front_buffer, NULL);
|
|
|
|
if (wined3d_texture_decref(swapchain->front_buffer))
|
2011-04-07 18:46:00 +02:00
|
|
|
WARN("Something's still holding the front buffer (%p).\n", swapchain->front_buffer);
|
|
|
|
swapchain->front_buffer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->back_buffers)
|
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
i = swapchain->state.desc.backbuffer_count;
|
2011-04-07 18:46:00 +02:00
|
|
|
|
|
|
|
while (i--)
|
|
|
|
{
|
2014-08-20 13:20:03 +02:00
|
|
|
wined3d_texture_set_swapchain(swapchain->back_buffers[i], NULL);
|
|
|
|
if (wined3d_texture_decref(swapchain->back_buffers[i]))
|
2011-04-07 18:46:00 +02:00
|
|
|
WARN("Something's still holding back buffer %u (%p).\n", i, swapchain->back_buffers[i]);
|
|
|
|
}
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(swapchain->back_buffers);
|
2011-04-07 18:46:00 +02:00
|
|
|
swapchain->back_buffers = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the screen resolution if we rendered in fullscreen.
|
|
|
|
* This will restore the screen resolution to what it was before creating
|
|
|
|
* the swapchain. In case of d3d8 and d3d9 this will be the original
|
|
|
|
* desktop resolution. In case of d3d7 this will be a NOP because ddraw
|
|
|
|
* sets the resolution before starting up Direct3D, thus orig_width and
|
|
|
|
* orig_height will be equal to the modes in the presentation params. */
|
2019-07-29 13:30:55 +02:00
|
|
|
if (!swapchain->state.desc.windowed)
|
2011-04-07 18:46:00 +02:00
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.auto_restore_display_mode)
|
2019-07-29 13:30:52 +02:00
|
|
|
{
|
2020-11-02 10:44:57 +01:00
|
|
|
if (FAILED(hr = wined3d_restore_display_modes(swapchain->device->wined3d)))
|
2019-07-29 13:30:52 +02:00
|
|
|
ERR("Failed to restore display mode, hr %#x.\n", hr);
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.flags & WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
|
2019-07-29 13:30:52 +02:00
|
|
|
{
|
2019-07-31 22:29:45 +02:00
|
|
|
wined3d_swapchain_state_restore_from_fullscreen(&swapchain->state,
|
2019-07-31 22:29:49 +02:00
|
|
|
swapchain->state.device_window, &swapchain->state.original_window_rect);
|
2019-07-29 13:30:52 +02:00
|
|
|
wined3d_device_release_focus_window(swapchain->device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-08-03 09:41:39 +02:00
|
|
|
{
|
2019-07-31 22:29:46 +02:00
|
|
|
wined3d_swapchain_state_restore_from_fullscreen(&swapchain->state, swapchain->state.device_window, NULL);
|
2016-08-03 09:41:39 +02:00
|
|
|
}
|
2011-04-07 18:46:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
static void wined3d_swapchain_gl_destroy_object(void *object)
|
|
|
|
{
|
|
|
|
wined3d_swapchain_gl_destroy_contexts(object);
|
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:37 +02:00
|
|
|
void wined3d_swapchain_gl_cleanup(struct wined3d_swapchain_gl *swapchain_gl)
|
|
|
|
{
|
2019-08-13 10:31:39 +02:00
|
|
|
struct wined3d_cs *cs = swapchain_gl->s.device->cs;
|
|
|
|
|
2019-08-13 10:31:37 +02:00
|
|
|
wined3d_swapchain_cleanup(&swapchain_gl->s);
|
2019-08-13 10:31:38 +02:00
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
wined3d_cs_destroy_object(cs, wined3d_swapchain_gl_destroy_object, swapchain_gl);
|
|
|
|
wined3d_cs_finish(cs, WINED3D_CS_QUEUE_DEFAULT);
|
|
|
|
|
2019-08-13 10:31:38 +02:00
|
|
|
if (swapchain_gl->backup_dc)
|
|
|
|
{
|
|
|
|
TRACE("Destroying backup wined3d window %p, dc %p.\n", swapchain_gl->backup_wnd, swapchain_gl->backup_dc);
|
|
|
|
|
|
|
|
wined3d_release_dc(swapchain_gl->backup_wnd, swapchain_gl->backup_dc);
|
|
|
|
DestroyWindow(swapchain_gl->backup_wnd);
|
|
|
|
}
|
2019-08-13 10:31:37 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 18:03:35 +02:00
|
|
|
static void wined3d_swapchain_vk_destroy_vulkan_swapchain(struct wined3d_swapchain_vk *swapchain_vk)
|
|
|
|
{
|
|
|
|
struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
|
|
|
|
const struct wined3d_vk_info *vk_info;
|
|
|
|
unsigned int i;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
TRACE("swapchain_vk %p.\n", swapchain_vk);
|
|
|
|
|
|
|
|
vk_info = &wined3d_adapter_vk(device_vk->d.adapter)->vk_info;
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkQueueWaitIdle(device_vk->vk_queue))) < 0)
|
|
|
|
ERR("Failed to wait on queue, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
heap_free(swapchain_vk->vk_images);
|
|
|
|
for (i = 0; i < swapchain_vk->image_count; ++i)
|
|
|
|
{
|
|
|
|
VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].available, NULL));
|
|
|
|
VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].presentable, NULL));
|
|
|
|
}
|
|
|
|
heap_free(swapchain_vk->vk_semaphores);
|
|
|
|
VK_CALL(vkDestroySwapchainKHR(device_vk->vk_device, swapchain_vk->vk_swapchain, NULL));
|
|
|
|
VK_CALL(vkDestroySurfaceKHR(vk_info->instance, swapchain_vk->vk_surface, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_swapchain_vk_destroy_object(void *object)
|
|
|
|
{
|
|
|
|
wined3d_swapchain_vk_destroy_vulkan_swapchain(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wined3d_swapchain_vk_cleanup(struct wined3d_swapchain_vk *swapchain_vk)
|
|
|
|
{
|
|
|
|
struct wined3d_cs *cs = swapchain_vk->s.device->cs;
|
|
|
|
|
|
|
|
wined3d_cs_destroy_object(cs, wined3d_swapchain_vk_destroy_object, swapchain_vk);
|
|
|
|
wined3d_cs_finish(cs, WINED3D_CS_QUEUE_DEFAULT);
|
|
|
|
|
|
|
|
wined3d_swapchain_cleanup(&swapchain_vk->s);
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
ULONG CDECL wined3d_swapchain_incref(struct wined3d_swapchain *swapchain)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedIncrement(&swapchain->ref);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u.\n", swapchain, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
ULONG CDECL wined3d_swapchain_decref(struct wined3d_swapchain *swapchain)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
|
|
|
ULONG refcount = InterlockedDecrement(&swapchain->ref);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", swapchain, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
2011-04-12 18:28:40 +02:00
|
|
|
{
|
2019-04-12 14:50:47 +02:00
|
|
|
struct wined3d_device *device;
|
|
|
|
|
2018-11-29 14:33:45 +01:00
|
|
|
wined3d_mutex_lock();
|
2017-05-02 11:35:30 +02:00
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
device = swapchain->device;
|
|
|
|
if (device->swapchain_count && device->swapchains[0] == swapchain)
|
|
|
|
wined3d_device_uninit_3d(device);
|
|
|
|
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
2017-05-02 11:35:30 +02:00
|
|
|
|
2011-04-12 18:28:40 +02:00
|
|
|
swapchain->parent_ops->wined3d_object_destroyed(swapchain->parent);
|
2019-08-08 00:47:04 +02:00
|
|
|
swapchain->device->adapter->adapter_ops->adapter_destroy_swapchain(swapchain);
|
2018-11-29 14:33:45 +01:00
|
|
|
|
|
|
|
wined3d_mutex_unlock();
|
2011-04-12 18:28:40 +02:00
|
|
|
}
|
2011-04-07 18:45:59 +02:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
void * CDECL wined3d_swapchain_get_parent(const struct wined3d_swapchain *swapchain)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
TRACE("swapchain %p.\n", swapchain);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
return swapchain->parent;
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
2012-10-02 22:15:39 +02:00
|
|
|
void CDECL wined3d_swapchain_set_window(struct wined3d_swapchain *swapchain, HWND window)
|
2011-04-12 18:28:41 +02:00
|
|
|
{
|
|
|
|
if (!window)
|
2019-07-31 22:29:46 +02:00
|
|
|
window = swapchain->state.device_window;
|
2011-04-12 18:28:41 +02:00
|
|
|
if (window == swapchain->win_handle)
|
2012-10-02 22:15:39 +02:00
|
|
|
return;
|
2011-04-12 18:28:41 +02:00
|
|
|
|
|
|
|
TRACE("Setting swapchain %p window from %p to %p.\n",
|
|
|
|
swapchain, swapchain->win_handle, window);
|
2018-06-11 12:05:06 +02:00
|
|
|
|
2018-11-29 14:33:47 +01:00
|
|
|
wined3d_cs_finish(swapchain->device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
2018-06-11 12:05:06 +02:00
|
|
|
|
2011-04-12 18:28:41 +02:00
|
|
|
swapchain->win_handle = window;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_present(struct wined3d_swapchain *swapchain,
|
2018-03-22 08:48:31 +01:00
|
|
|
const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
|
|
|
|
unsigned int swap_interval, DWORD flags)
|
2011-04-13 19:14:30 +02:00
|
|
|
{
|
2016-03-17 16:30:04 +01:00
|
|
|
RECT s, d;
|
|
|
|
|
2019-03-17 18:51:04 +01:00
|
|
|
TRACE("swapchain %p, src_rect %s, dst_rect %s, dst_window_override %p, swap_interval %u, flags %#x.\n",
|
2011-04-13 19:14:31 +02:00
|
|
|
swapchain, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
|
2019-03-17 18:51:04 +01:00
|
|
|
dst_window_override, swap_interval, flags);
|
2011-04-13 19:14:30 +02:00
|
|
|
|
2012-06-29 07:37:56 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
|
|
|
|
2018-12-03 14:41:05 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2012-04-15 18:57:13 +02:00
|
|
|
if (!swapchain->back_buffers)
|
|
|
|
{
|
2018-03-22 08:48:31 +01:00
|
|
|
WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL.\n");
|
2018-12-03 14:41:05 +01:00
|
|
|
wined3d_mutex_unlock();
|
2012-04-15 18:57:13 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:30:04 +01:00
|
|
|
if (!src_rect)
|
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
SetRect(&s, 0, 0, swapchain->state.desc.backbuffer_width,
|
|
|
|
swapchain->state.desc.backbuffer_height);
|
2016-03-17 16:30:04 +01:00
|
|
|
src_rect = &s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dst_rect)
|
|
|
|
{
|
|
|
|
GetClientRect(swapchain->win_handle, &d);
|
|
|
|
dst_rect = &d;
|
|
|
|
}
|
|
|
|
|
2013-09-27 00:15:13 +02:00
|
|
|
wined3d_cs_emit_present(swapchain->device->cs, swapchain, src_rect,
|
2018-03-22 08:48:31 +01:00
|
|
|
dst_rect, dst_window_override, swap_interval, flags);
|
2012-04-15 18:57:13 +02:00
|
|
|
|
2018-12-03 14:41:05 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2012-04-15 18:57:13 +02:00
|
|
|
return WINED3D_OK;
|
2011-04-13 19:14:30 +02:00
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_get_front_buffer_data(const struct wined3d_swapchain *swapchain,
|
2015-10-16 13:59:17 +02:00
|
|
|
struct wined3d_texture *dst_texture, unsigned int sub_resource_idx)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
2011-11-02 22:46:53 +01:00
|
|
|
RECT src_rect, dst_rect;
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2015-10-16 13:59:17 +02:00
|
|
|
TRACE("swapchain %p, dst_texture %p, sub_resource_idx %u.\n", swapchain, dst_texture, sub_resource_idx);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2016-03-25 17:52:29 +01:00
|
|
|
SetRect(&src_rect, 0, 0, swapchain->front_buffer->resource.width, swapchain->front_buffer->resource.height);
|
2011-11-02 22:46:53 +01:00
|
|
|
dst_rect = src_rect;
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.windowed)
|
2011-11-02 22:46:53 +01:00
|
|
|
{
|
|
|
|
MapWindowPoints(swapchain->win_handle, NULL, (POINT *)&dst_rect, 2);
|
|
|
|
FIXME("Using destination rect %s in windowed mode, this is likely wrong.\n",
|
|
|
|
wine_dbgstr_rect(&dst_rect));
|
|
|
|
}
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2016-03-25 17:52:29 +01:00
|
|
|
return wined3d_texture_blt(dst_texture, sub_resource_idx, &dst_rect,
|
|
|
|
swapchain->front_buffer, 0, &src_rect, 0, NULL, WINED3D_TEXF_POINT);
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
2015-09-03 12:52:52 +02:00
|
|
|
struct wined3d_texture * CDECL wined3d_swapchain_get_back_buffer(const struct wined3d_swapchain *swapchain,
|
2015-09-07 23:50:34 +02:00
|
|
|
UINT back_buffer_idx)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
2015-09-07 23:50:34 +02:00
|
|
|
TRACE("swapchain %p, back_buffer_idx %u.\n",
|
|
|
|
swapchain, back_buffer_idx);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
|
|
|
/* Return invalid if there is no backbuffer array, otherwise it will
|
|
|
|
* crash when ddraw is used (there swapchain->back_buffers is always
|
|
|
|
* NULL). We need this because this function is called from
|
|
|
|
* stateblock_init_default_state() to get the default scissorrect
|
|
|
|
* dimensions. */
|
2019-07-29 13:30:55 +02:00
|
|
|
if (!swapchain->back_buffers || back_buffer_idx >= swapchain->state.desc.backbuffer_count)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
|
|
|
WARN("Invalid back buffer index.\n");
|
|
|
|
/* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it
|
|
|
|
* here in wined3d to avoid problems in other libs. */
|
2012-10-04 13:53:27 +02:00
|
|
|
return NULL;
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
2012-10-04 13:53:27 +02:00
|
|
|
TRACE("Returning back buffer %p.\n", swapchain->back_buffers[back_buffer_idx]);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2015-09-03 12:52:52 +02:00
|
|
|
return swapchain->back_buffers[back_buffer_idx];
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
2020-03-05 16:04:29 +01:00
|
|
|
struct wined3d_output * wined3d_swapchain_get_output(const struct wined3d_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
TRACE("swapchain %p.\n", swapchain);
|
|
|
|
|
2020-05-12 14:50:12 +02:00
|
|
|
return swapchain->state.desc.output;
|
2020-03-05 16:04:29 +01:00
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_get_raster_status(const struct wined3d_swapchain *swapchain,
|
2011-12-02 08:15:53 +01:00
|
|
|
struct wined3d_raster_status *raster_status)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
2020-03-09 08:40:21 +01:00
|
|
|
struct wined3d_output *output;
|
|
|
|
|
2012-07-18 21:32:30 +02:00
|
|
|
TRACE("swapchain %p, raster_status %p.\n", swapchain, raster_status);
|
2012-01-18 15:33:53 +01:00
|
|
|
|
2020-03-09 08:40:21 +01:00
|
|
|
output = wined3d_swapchain_get_output(swapchain);
|
|
|
|
if (!output)
|
|
|
|
{
|
|
|
|
ERR("Failed to get output from swapchain %p.\n", swapchain);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wined3d_output_get_raster_status(output, raster_status);
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
struct wined3d_swapchain_state * CDECL wined3d_swapchain_get_state(struct wined3d_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
return &swapchain->state;
|
|
|
|
}
|
|
|
|
|
2011-11-16 20:08:06 +01:00
|
|
|
HRESULT CDECL wined3d_swapchain_get_display_mode(const struct wined3d_swapchain *swapchain,
|
2012-06-27 19:02:29 +02:00
|
|
|
struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
2020-03-06 14:16:29 +01:00
|
|
|
struct wined3d_output *output;
|
2011-04-07 18:45:59 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2012-06-27 19:02:29 +02:00
|
|
|
TRACE("swapchain %p, mode %p, rotation %p.\n", swapchain, mode, rotation);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2020-03-06 14:16:29 +01:00
|
|
|
if (!(output = wined3d_swapchain_get_output(swapchain)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get output from swapchain %p.\n", swapchain);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = wined3d_output_get_display_mode(output, mode, rotation);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
|
|
|
TRACE("Returning w %u, h %u, refresh rate %u, format %s.\n",
|
2011-11-16 20:08:06 +01:00
|
|
|
mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id));
|
2011-04-07 18:45:59 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
struct wined3d_device * CDECL wined3d_swapchain_get_device(const struct wined3d_swapchain *swapchain)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
TRACE("swapchain %p.\n", swapchain);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2011-05-16 23:01:23 +02:00
|
|
|
return swapchain->device;
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
2012-10-04 13:53:28 +02:00
|
|
|
void CDECL wined3d_swapchain_get_desc(const struct wined3d_swapchain *swapchain,
|
2011-12-02 08:15:52 +01:00
|
|
|
struct wined3d_swapchain_desc *desc)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("swapchain %p, desc %p.\n", swapchain, desc);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
*desc = swapchain->state.desc;
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_set_gamma_ramp(const struct wined3d_swapchain *swapchain,
|
2011-11-21 18:48:41 +01:00
|
|
|
DWORD flags, const struct wined3d_gamma_ramp *ramp)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
|
|
|
HDC dc;
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
TRACE("swapchain %p, flags %#x, ramp %p.\n", swapchain, flags, ramp);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
dc = GetDCEx(swapchain->state.device_window, 0, DCX_USESTYLE | DCX_CACHE);
|
2011-04-07 18:45:59 +02:00
|
|
|
SetDeviceGammaRamp(dc, (void *)ramp);
|
2019-07-31 22:29:46 +02:00
|
|
|
ReleaseDC(swapchain->state.device_window, dc);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-28 10:49:32 +02:00
|
|
|
void CDECL wined3d_swapchain_set_palette(struct wined3d_swapchain *swapchain, struct wined3d_palette *palette)
|
|
|
|
{
|
|
|
|
TRACE("swapchain %p, palette %p.\n", swapchain, palette);
|
2019-01-12 12:23:17 +01:00
|
|
|
|
|
|
|
wined3d_cs_finish(swapchain->device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
|
|
|
|
2014-06-28 10:49:32 +02:00
|
|
|
swapchain->palette = palette;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_get_gamma_ramp(const struct wined3d_swapchain *swapchain,
|
2011-11-21 18:48:41 +01:00
|
|
|
struct wined3d_gamma_ramp *ramp)
|
2011-04-07 18:45:59 +02:00
|
|
|
{
|
|
|
|
HDC dc;
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
TRACE("swapchain %p, ramp %p.\n", swapchain, ramp);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
dc = GetDCEx(swapchain->state.device_window, 0, DCX_USESTYLE | DCX_CACHE);
|
2011-04-07 18:45:59 +02:00
|
|
|
GetDeviceGammaRamp(dc, ramp);
|
2019-07-31 22:29:46 +02:00
|
|
|
ReleaseDC(swapchain->state.device_window, dc);
|
2011-04-07 18:45:59 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2009-12-06 17:39:47 +01:00
|
|
|
/* A GL context is provided by the caller */
|
2011-07-15 01:14:53 +02:00
|
|
|
static void swapchain_blit(const struct wined3d_swapchain *swapchain,
|
2011-04-13 19:14:32 +02:00
|
|
|
struct wined3d_context *context, const RECT *src_rect, const RECT *dst_rect)
|
2009-12-06 17:39:47 +01:00
|
|
|
{
|
2016-03-28 18:57:57 +02:00
|
|
|
struct wined3d_texture *texture = swapchain->back_buffers[0];
|
2017-03-30 23:15:32 +02:00
|
|
|
struct wined3d_device *device = swapchain->device;
|
2017-03-22 23:11:28 +01:00
|
|
|
enum wined3d_texture_filter_type filter;
|
2017-03-30 23:15:32 +02:00
|
|
|
DWORD location;
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2010-01-03 21:18:25 +01:00
|
|
|
TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n",
|
2011-04-13 19:14:32 +02:00
|
|
|
swapchain, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
|
2010-01-03 21:18:25 +01:00
|
|
|
|
2017-03-30 23:15:32 +02:00
|
|
|
if ((src_rect->right - src_rect->left == dst_rect->right - dst_rect->left
|
|
|
|
&& src_rect->bottom - src_rect->top == dst_rect->bottom - dst_rect->top)
|
|
|
|
|| is_complex_fixup(texture->resource.format->color_fixup))
|
|
|
|
filter = WINED3D_TEXF_NONE;
|
2009-12-06 17:39:47 +01:00
|
|
|
else
|
2017-03-30 23:15:32 +02:00
|
|
|
filter = WINED3D_TEXF_LINEAR;
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2017-03-30 23:15:32 +02:00
|
|
|
location = WINED3D_LOCATION_TEXTURE_RGB;
|
|
|
|
if (texture->resource.multisample_type)
|
|
|
|
location = WINED3D_LOCATION_RB_RESOLVED;
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2017-03-30 23:15:32 +02:00
|
|
|
wined3d_texture_validate_location(texture, 0, WINED3D_LOCATION_DRAWABLE);
|
2018-03-13 11:23:01 +01:00
|
|
|
device->blitter->ops->blitter_blit(device->blitter, WINED3D_BLIT_OP_COLOR_BLIT, context, texture, 0,
|
|
|
|
location, src_rect, texture, 0, WINED3D_LOCATION_DRAWABLE, dst_rect, NULL, filter);
|
2017-03-30 23:15:32 +02:00
|
|
|
wined3d_texture_invalidate_location(texture, 0, WINED3D_LOCATION_DRAWABLE);
|
2009-12-06 17:39:47 +01:00
|
|
|
}
|
|
|
|
|
2019-03-17 18:51:04 +01:00
|
|
|
static void swapchain_gl_set_swap_interval(struct wined3d_swapchain *swapchain,
|
2019-08-02 01:02:09 +02:00
|
|
|
struct wined3d_context_gl *context_gl, unsigned int swap_interval)
|
2019-03-17 18:51:04 +01:00
|
|
|
{
|
2019-08-07 13:41:58 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = context_gl->gl_info;
|
2019-03-17 18:51:04 +01:00
|
|
|
|
|
|
|
swap_interval = swap_interval <= 4 ? swap_interval : 1;
|
|
|
|
if (swapchain->swap_interval == swap_interval)
|
|
|
|
return;
|
|
|
|
|
|
|
|
swapchain->swap_interval = swap_interval;
|
|
|
|
|
|
|
|
if (!gl_info->supported[WGL_EXT_SWAP_CONTROL])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!GL_EXTCALL(wglSwapIntervalEXT(swap_interval)))
|
|
|
|
{
|
|
|
|
ERR("Failed to set swap interval %u for context %p, last error %#x.\n",
|
2019-08-02 01:02:09 +02:00
|
|
|
swap_interval, context_gl, GetLastError());
|
2019-03-17 18:51:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 23:28:08 +01:00
|
|
|
/* Context activation is done by the caller. */
|
2018-10-29 08:17:11 +01:00
|
|
|
static void wined3d_swapchain_gl_rotate(struct wined3d_swapchain *swapchain, struct wined3d_context *context)
|
2016-02-24 23:28:08 +01:00
|
|
|
{
|
2016-03-28 18:58:01 +02:00
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
2018-10-29 08:17:11 +01:00
|
|
|
struct wined3d_texture_gl *texture, *texture_prev;
|
2016-02-24 23:28:08 +01:00
|
|
|
struct gl_texture tex0;
|
|
|
|
GLuint rb0;
|
|
|
|
DWORD locations0;
|
|
|
|
unsigned int i;
|
|
|
|
static const DWORD supported_locations = WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_RB_MULTISAMPLE;
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.backbuffer_count < 2 || !swapchain->render_to_fbo)
|
2016-02-24 23:28:08 +01:00
|
|
|
return;
|
|
|
|
|
2018-10-29 08:17:11 +01:00
|
|
|
texture_prev = wined3d_texture_gl(swapchain->back_buffers[0]);
|
2016-02-24 23:28:08 +01:00
|
|
|
|
|
|
|
/* Back buffer 0 is already in the draw binding. */
|
2018-10-30 10:48:43 +01:00
|
|
|
tex0 = texture_prev->texture_rgb;
|
2016-04-18 19:06:26 +02:00
|
|
|
rb0 = texture_prev->rb_multisample;
|
2018-10-29 08:17:11 +01:00
|
|
|
locations0 = texture_prev->t.sub_resources[0].locations;
|
2016-02-24 23:28:08 +01:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
for (i = 1; i < swapchain->state.desc.backbuffer_count; ++i)
|
2016-02-24 23:28:08 +01:00
|
|
|
{
|
2018-10-29 08:17:11 +01:00
|
|
|
texture = wined3d_texture_gl(swapchain->back_buffers[i]);
|
|
|
|
sub_resource = &texture->t.sub_resources[0];
|
2016-02-24 23:28:08 +01:00
|
|
|
|
2016-03-28 18:58:01 +02:00
|
|
|
if (!(sub_resource->locations & supported_locations))
|
2018-10-29 08:17:11 +01:00
|
|
|
wined3d_texture_load_location(&texture->t, 0, context, texture->t.resource.draw_binding);
|
2016-02-24 23:28:08 +01:00
|
|
|
|
2018-10-30 10:48:43 +01:00
|
|
|
texture_prev->texture_rgb = texture->texture_rgb;
|
2016-04-18 19:06:26 +02:00
|
|
|
texture_prev->rb_multisample = texture->rb_multisample;
|
2016-02-24 23:28:08 +01:00
|
|
|
|
2018-10-29 08:17:11 +01:00
|
|
|
wined3d_texture_validate_location(&texture_prev->t, 0, sub_resource->locations & supported_locations);
|
|
|
|
wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(sub_resource->locations & supported_locations));
|
2016-02-24 23:28:08 +01:00
|
|
|
|
2016-03-30 21:30:19 +02:00
|
|
|
texture_prev = texture;
|
2016-02-24 23:28:08 +01:00
|
|
|
}
|
|
|
|
|
2018-10-30 10:48:43 +01:00
|
|
|
texture_prev->texture_rgb = tex0;
|
2016-04-18 19:06:26 +02:00
|
|
|
texture_prev->rb_multisample = rb0;
|
2016-02-24 23:28:08 +01:00
|
|
|
|
2018-10-29 08:17:11 +01:00
|
|
|
wined3d_texture_validate_location(&texture_prev->t, 0, locations0 & supported_locations);
|
|
|
|
wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(locations0 & supported_locations));
|
2016-02-24 23:28:08 +01:00
|
|
|
|
|
|
|
device_invalidate_state(swapchain->device, STATE_FRAMEBUFFER);
|
|
|
|
}
|
|
|
|
|
2016-03-17 16:30:03 +01:00
|
|
|
static void swapchain_gl_present(struct wined3d_swapchain *swapchain,
|
2019-03-17 18:51:04 +01:00
|
|
|
const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2019-08-13 10:31:39 +02:00
|
|
|
struct wined3d_swapchain_gl *swapchain_gl = wined3d_swapchain_gl(swapchain);
|
2019-07-29 13:30:55 +02:00
|
|
|
const struct wined3d_swapchain_desc *desc = &swapchain->state.desc;
|
2016-08-04 12:06:58 +02:00
|
|
|
struct wined3d_texture *back_buffer = swapchain->back_buffers[0];
|
2010-05-24 09:56:35 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2019-06-03 15:40:22 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2010-01-03 21:18:26 +01:00
|
|
|
BOOL render_to_fbo;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2019-07-29 12:44:46 +02:00
|
|
|
context = context_acquire(swapchain->device, swapchain->front_buffer, 0);
|
2019-06-06 14:51:06 +02:00
|
|
|
context_gl = wined3d_context_gl(context);
|
|
|
|
if (!context_gl->valid)
|
2010-03-17 21:59:54 +01:00
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping present.\n");
|
2012-04-15 18:57:13 +02:00
|
|
|
return;
|
2010-03-17 21:59:54 +01:00
|
|
|
}
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2019-08-07 13:41:58 +02:00
|
|
|
gl_info = context_gl->gl_info;
|
2010-05-24 09:56:35 +02:00
|
|
|
|
2019-08-02 01:02:09 +02:00
|
|
|
swapchain_gl_set_swap_interval(swapchain, context_gl, swap_interval);
|
2019-03-17 18:51:04 +01:00
|
|
|
|
2019-06-03 15:40:22 +02:00
|
|
|
TRACE("Presenting DC %p.\n", context_gl->dc);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2016-03-17 16:30:04 +01:00
|
|
|
if (!(render_to_fbo = swapchain->render_to_fbo)
|
|
|
|
&& (src_rect->left || src_rect->top
|
2019-07-29 13:30:55 +02:00
|
|
|
|| src_rect->right != desc->backbuffer_width
|
|
|
|
|| src_rect->bottom != desc->backbuffer_height
|
2016-03-17 16:30:04 +01:00
|
|
|
|| dst_rect->left || dst_rect->top
|
2019-07-29 13:30:55 +02:00
|
|
|
|| dst_rect->right != desc->backbuffer_width
|
|
|
|
|| dst_rect->bottom != desc->backbuffer_height))
|
2010-01-03 21:18:26 +01:00
|
|
|
render_to_fbo = TRUE;
|
|
|
|
|
2009-11-24 12:31:39 +01:00
|
|
|
/* Rendering to a window of different size, presenting partial rectangles,
|
|
|
|
* or rendering to a different window needs help from FBO_blit or a textured
|
|
|
|
* draw. Render the swapchain to a FBO in the future.
|
|
|
|
*
|
|
|
|
* Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
|
|
|
|
* all these issues - this fails if the window is smaller than the backbuffer.
|
|
|
|
*/
|
2011-04-13 19:14:30 +02:00
|
|
|
if (!swapchain->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
2009-11-24 12:31:39 +01:00
|
|
|
{
|
2016-08-04 12:06:58 +02:00
|
|
|
wined3d_texture_load_location(back_buffer, 0, context, WINED3D_LOCATION_TEXTURE_RGB);
|
|
|
|
wined3d_texture_invalidate_location(back_buffer, 0, WINED3D_LOCATION_DRAWABLE);
|
2011-04-13 19:14:30 +02:00
|
|
|
swapchain->render_to_fbo = TRUE;
|
2011-08-23 20:08:08 +02:00
|
|
|
swapchain_update_draw_bindings(swapchain);
|
2009-11-24 12:31:39 +01:00
|
|
|
}
|
2012-03-26 20:28:10 +02:00
|
|
|
else
|
|
|
|
{
|
2016-08-04 12:06:58 +02:00
|
|
|
wined3d_texture_load_location(back_buffer, 0, context, back_buffer->resource.draw_binding);
|
2012-03-26 20:28:10 +02:00
|
|
|
}
|
2009-11-24 12:31:39 +01:00
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
if (swapchain->render_to_fbo)
|
2016-03-17 16:30:04 +01:00
|
|
|
swapchain_blit(swapchain, context, src_rect, dst_rect);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
if (swapchain_gl->context_count > 1)
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glFinish();
|
2012-12-06 14:10:04 +01:00
|
|
|
|
|
|
|
/* call wglSwapBuffers through the gl table to avoid confusing the Steam overlay */
|
2019-06-03 15:40:22 +02:00
|
|
|
gl_info->gl_ops.wgl.p_wglSwapBuffers(context_gl->dc);
|
2020-11-30 15:41:25 +01:00
|
|
|
wined3d_context_gl_submit_command_fence(context_gl);
|
2016-02-24 23:28:08 +01:00
|
|
|
|
2018-10-29 08:17:11 +01:00
|
|
|
wined3d_swapchain_gl_rotate(swapchain, context);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2007-08-08 03:09:38 +02:00
|
|
|
TRACE("SwapBuffers called, Starting new frame\n");
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(swapchain->front_buffer, 0, WINED3D_LOCATION_DRAWABLE);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(swapchain->front_buffer, 0, ~WINED3D_LOCATION_DRAWABLE);
|
2007-06-03 13:20:27 +02:00
|
|
|
|
2009-10-28 11:00:11 +01:00
|
|
|
context_release(context);
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
static void swapchain_frontbuffer_updated(struct wined3d_swapchain *swapchain)
|
2016-03-01 19:31:49 +01:00
|
|
|
{
|
2016-08-04 12:06:59 +02:00
|
|
|
struct wined3d_texture *front_buffer = swapchain->front_buffer;
|
2016-03-01 19:31:49 +01:00
|
|
|
struct wined3d_context *context;
|
|
|
|
|
2017-02-15 14:17:15 +01:00
|
|
|
context = context_acquire(swapchain->device, front_buffer, 0);
|
2016-08-04 12:06:59 +02:00
|
|
|
wined3d_texture_load_location(front_buffer, 0, context, front_buffer->resource.draw_binding);
|
2016-03-01 19:31:49 +01:00
|
|
|
context_release(context);
|
|
|
|
SetRectEmpty(&swapchain->front_buffer_update);
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
static const struct wined3d_swapchain_ops swapchain_gl_ops =
|
2005-06-23 13:05:24 +02:00
|
|
|
{
|
2011-04-13 19:14:30 +02:00
|
|
|
swapchain_gl_present,
|
2019-08-08 00:47:04 +02:00
|
|
|
swapchain_frontbuffer_updated,
|
|
|
|
};
|
|
|
|
|
2020-05-29 18:03:35 +02:00
|
|
|
static bool wined3d_swapchain_vk_present_mode_supported(struct wined3d_swapchain_vk *swapchain_vk,
|
|
|
|
VkPresentModeKHR vk_present_mode)
|
|
|
|
{
|
|
|
|
struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
|
|
|
|
const struct wined3d_vk_info *vk_info;
|
|
|
|
struct wined3d_adapter_vk *adapter_vk;
|
|
|
|
VkPhysicalDevice vk_physical_device;
|
|
|
|
VkPresentModeKHR *vk_modes;
|
|
|
|
bool supported = false;
|
|
|
|
uint32_t count, i;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
adapter_vk = wined3d_adapter_vk(device_vk->d.adapter);
|
|
|
|
vk_physical_device = adapter_vk->physical_device;
|
|
|
|
vk_info = &adapter_vk->vk_info;
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physical_device,
|
|
|
|
swapchain_vk->vk_surface, &count, NULL))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to get supported present mode count, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(vk_modes = heap_calloc(count, sizeof(*vk_modes))))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physical_device,
|
|
|
|
swapchain_vk->vk_surface, &count, vk_modes))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to get supported present modes, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
if (vk_modes[i] == vk_present_mode)
|
|
|
|
{
|
|
|
|
supported = true;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
heap_free(vk_modes);
|
|
|
|
return supported;
|
|
|
|
}
|
|
|
|
|
2020-12-09 12:34:56 +01:00
|
|
|
static VkFormat get_swapchain_fallback_format(VkFormat vk_format)
|
|
|
|
{
|
|
|
|
switch (vk_format)
|
|
|
|
{
|
|
|
|
case VK_FORMAT_R8G8B8A8_SRGB:
|
|
|
|
return VK_FORMAT_B8G8R8A8_SRGB;
|
|
|
|
case VK_FORMAT_R8G8B8A8_UNORM:
|
|
|
|
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
|
|
|
|
case VK_FORMAT_R16G16B16A16_SFLOAT:
|
|
|
|
return VK_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
default:
|
|
|
|
WARN("Unhandled format %#x.\n", vk_format);
|
|
|
|
return VK_FORMAT_UNDEFINED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-29 18:03:35 +02:00
|
|
|
static VkFormat wined3d_swapchain_vk_select_vk_format(struct wined3d_swapchain_vk *swapchain_vk,
|
|
|
|
VkSurfaceKHR vk_surface)
|
|
|
|
{
|
|
|
|
struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
|
|
|
|
const struct wined3d_swapchain_desc *desc = &swapchain_vk->s.state.desc;
|
|
|
|
const struct wined3d_vk_info *vk_info;
|
|
|
|
struct wined3d_adapter_vk *adapter_vk;
|
|
|
|
const struct wined3d_format *format;
|
|
|
|
VkPhysicalDevice vk_physical_device;
|
|
|
|
VkSurfaceFormatKHR *vk_formats;
|
|
|
|
uint32_t format_count, i;
|
|
|
|
VkFormat vk_format;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
adapter_vk = wined3d_adapter_vk(device_vk->d.adapter);
|
|
|
|
vk_physical_device = adapter_vk->physical_device;
|
|
|
|
vk_info = &adapter_vk->vk_info;
|
|
|
|
|
|
|
|
if ((format = wined3d_get_format(&adapter_vk->a, desc->backbuffer_format, WINED3D_BIND_RENDER_TARGET)))
|
|
|
|
vk_format = wined3d_format_vk(format)->vk_format;
|
|
|
|
else
|
|
|
|
vk_format = VK_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
|
|
|
|
vr = VK_CALL(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical_device, vk_surface, &format_count, NULL));
|
|
|
|
if (vr < 0 || !format_count)
|
|
|
|
{
|
|
|
|
WARN("Failed to get supported surface format count, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
return VK_FORMAT_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(vk_formats = heap_calloc(format_count, sizeof(*vk_formats))))
|
|
|
|
return VK_FORMAT_UNDEFINED;
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical_device,
|
|
|
|
vk_surface, &format_count, vk_formats))) < 0)
|
|
|
|
{
|
|
|
|
WARN("Failed to get supported surface formats, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
heap_free(vk_formats);
|
|
|
|
return VK_FORMAT_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < format_count; ++i)
|
|
|
|
{
|
|
|
|
if (vk_formats[i].format == vk_format && vk_formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == format_count)
|
|
|
|
{
|
|
|
|
/* Try to create a swapchain with format conversion. */
|
2020-12-09 12:34:56 +01:00
|
|
|
vk_format = get_swapchain_fallback_format(vk_format);
|
2020-05-29 18:03:35 +02:00
|
|
|
WARN("Failed to find Vulkan swapchain format for %s.\n", debug_d3dformat(desc->backbuffer_format));
|
|
|
|
for (i = 0; i < format_count; ++i)
|
|
|
|
{
|
|
|
|
if (vk_formats[i].format == vk_format && vk_formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap_free(vk_formats);
|
|
|
|
if (i == format_count)
|
|
|
|
{
|
|
|
|
FIXME("Failed to find Vulkan swapchain format for %s.\n", debug_d3dformat(desc->backbuffer_format));
|
|
|
|
return VK_FORMAT_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Using Vulkan swapchain format %#x.\n", vk_format);
|
|
|
|
|
|
|
|
return vk_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool wined3d_swapchain_vk_create_vulkan_swapchain_images(struct wined3d_swapchain_vk *swapchain_vk,
|
|
|
|
VkSwapchainKHR vk_swapchain)
|
|
|
|
{
|
|
|
|
struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
|
|
|
|
const struct wined3d_vk_info *vk_info;
|
|
|
|
VkSemaphoreCreateInfo semaphore_info;
|
|
|
|
uint32_t image_count, i;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
vk_info = &wined3d_adapter_vk(device_vk->d.adapter)->vk_info;
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkGetSwapchainImagesKHR(device_vk->vk_device, vk_swapchain, &image_count, NULL))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to get image count, vr %s\n", wined3d_debug_vkresult(vr));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(swapchain_vk->vk_images = heap_calloc(image_count, sizeof(*swapchain_vk->vk_images))))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate images array.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkGetSwapchainImagesKHR(device_vk->vk_device,
|
|
|
|
vk_swapchain, &image_count, swapchain_vk->vk_images))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to get swapchain images, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
heap_free(swapchain_vk->vk_images);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(swapchain_vk->vk_semaphores = heap_calloc(image_count, sizeof(*swapchain_vk->vk_semaphores))))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate semaphores array.\n");
|
|
|
|
heap_free(swapchain_vk->vk_images);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
|
|
|
semaphore_info.pNext = NULL;
|
|
|
|
semaphore_info.flags = 0;
|
|
|
|
for (i = 0; i < image_count; ++i)
|
|
|
|
{
|
|
|
|
if ((vr = VK_CALL(vkCreateSemaphore(device_vk->vk_device,
|
|
|
|
&semaphore_info, NULL, &swapchain_vk->vk_semaphores[i].available))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to create semaphore, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkCreateSemaphore(device_vk->vk_device,
|
|
|
|
&semaphore_info, NULL, &swapchain_vk->vk_semaphores[i].presentable))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to create semaphore, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
swapchain_vk->image_count = image_count;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
for (i = 0; i < image_count; ++i)
|
|
|
|
{
|
|
|
|
if (swapchain_vk->vk_semaphores[i].available)
|
|
|
|
VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].available, NULL));
|
|
|
|
if (swapchain_vk->vk_semaphores[i].presentable)
|
|
|
|
VK_CALL(vkDestroySemaphore(device_vk->vk_device, swapchain_vk->vk_semaphores[i].presentable, NULL));
|
|
|
|
}
|
|
|
|
heap_free(swapchain_vk->vk_semaphores);
|
|
|
|
heap_free(swapchain_vk->vk_images);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT wined3d_swapchain_vk_create_vulkan_swapchain(struct wined3d_swapchain_vk *swapchain_vk)
|
|
|
|
{
|
|
|
|
struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
|
|
|
|
const struct wined3d_swapchain_desc *desc = &swapchain_vk->s.state.desc;
|
|
|
|
VkSwapchainCreateInfoKHR vk_swapchain_desc;
|
|
|
|
VkWin32SurfaceCreateInfoKHR surface_desc;
|
|
|
|
unsigned int width, height, image_count;
|
|
|
|
const struct wined3d_vk_info *vk_info;
|
|
|
|
VkSurfaceCapabilitiesKHR surface_caps;
|
|
|
|
struct wined3d_adapter_vk *adapter_vk;
|
|
|
|
VkPresentModeKHR vk_present_mode;
|
|
|
|
VkSwapchainKHR vk_swapchain;
|
|
|
|
VkImageUsageFlags usage;
|
|
|
|
VkSurfaceKHR vk_surface;
|
|
|
|
VkBool32 supported;
|
|
|
|
VkFormat vk_format;
|
|
|
|
VkResult vr;
|
|
|
|
|
|
|
|
adapter_vk = wined3d_adapter_vk(device_vk->d.adapter);
|
|
|
|
vk_info = &adapter_vk->vk_info;
|
|
|
|
|
|
|
|
surface_desc.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
|
|
|
|
surface_desc.pNext = NULL;
|
|
|
|
surface_desc.flags = 0;
|
|
|
|
surface_desc.hinstance = (HINSTANCE)GetWindowLongPtrW(swapchain_vk->s.win_handle, GWLP_HINSTANCE);
|
|
|
|
surface_desc.hwnd = swapchain_vk->s.win_handle;
|
|
|
|
if ((vr = VK_CALL(vkCreateWin32SurfaceKHR(vk_info->instance, &surface_desc, NULL, &vk_surface))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to create Vulkan surface, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
swapchain_vk->vk_surface = vk_surface;
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkGetPhysicalDeviceSurfaceSupportKHR(adapter_vk->physical_device,
|
|
|
|
device_vk->vk_queue_family_index, vk_surface, &supported))) < 0 || !supported)
|
|
|
|
{
|
|
|
|
ERR("Queue family does not support presentation on this surface, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vk_format = wined3d_swapchain_vk_select_vk_format(swapchain_vk, vk_surface)) == VK_FORMAT_UNDEFINED)
|
|
|
|
{
|
|
|
|
ERR("Failed to select swapchain format.\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((vr = VK_CALL(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(adapter_vk->physical_device,
|
|
|
|
swapchain_vk->vk_surface, &surface_caps))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to get surface capabilities, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
image_count = desc->backbuffer_count;
|
|
|
|
if (image_count < surface_caps.minImageCount)
|
|
|
|
image_count = surface_caps.minImageCount;
|
|
|
|
else if (surface_caps.maxImageCount && image_count > surface_caps.maxImageCount)
|
|
|
|
image_count = surface_caps.maxImageCount;
|
|
|
|
|
|
|
|
if (image_count != desc->backbuffer_count)
|
|
|
|
WARN("Image count %u is not supported (%u-%u).\n", desc->backbuffer_count,
|
|
|
|
surface_caps.minImageCount, surface_caps.maxImageCount);
|
|
|
|
|
|
|
|
width = desc->backbuffer_width;
|
|
|
|
if (width < surface_caps.minImageExtent.width)
|
|
|
|
width = surface_caps.minImageExtent.width;
|
|
|
|
else if (width > surface_caps.maxImageExtent.width)
|
|
|
|
width = surface_caps.maxImageExtent.width;
|
|
|
|
|
|
|
|
height = desc->backbuffer_height;
|
|
|
|
if (height < surface_caps.minImageExtent.height)
|
|
|
|
height = surface_caps.minImageExtent.height;
|
|
|
|
else if (height > surface_caps.maxImageExtent.height)
|
|
|
|
height = surface_caps.maxImageExtent.height;
|
|
|
|
|
|
|
|
if (width != desc->backbuffer_width || height != desc->backbuffer_height)
|
|
|
|
WARN("Swapchain dimensions %ux%u are not supported (%u-%u x %u-%u).\n",
|
|
|
|
desc->backbuffer_width, desc->backbuffer_height,
|
|
|
|
surface_caps.minImageExtent.width, surface_caps.maxImageExtent.width,
|
|
|
|
surface_caps.minImageExtent.height, surface_caps.maxImageExtent.height);
|
|
|
|
|
|
|
|
usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
|
|
|
usage |= surface_caps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
|
|
|
usage |= surface_caps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT;
|
|
|
|
if (!(usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) || !(usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT))
|
|
|
|
WARN("Transfer not supported for swapchain images.\n");
|
|
|
|
|
|
|
|
if (!(surface_caps.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR))
|
|
|
|
{
|
|
|
|
FIXME("Unsupported alpha mode, %#x.\n", surface_caps.supportedCompositeAlpha);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
vk_present_mode = VK_PRESENT_MODE_FIFO_KHR;
|
|
|
|
if (!swapchain_vk->s.swap_interval)
|
|
|
|
{
|
|
|
|
if (wined3d_swapchain_vk_present_mode_supported(swapchain_vk, VK_PRESENT_MODE_IMMEDIATE_KHR))
|
|
|
|
vk_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
|
|
|
|
else
|
|
|
|
FIXME("Unsupported swap interval %u.\n", swapchain_vk->s.swap_interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
vk_swapchain_desc.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
|
|
|
vk_swapchain_desc.pNext = NULL;
|
|
|
|
vk_swapchain_desc.flags = 0;
|
|
|
|
vk_swapchain_desc.surface = vk_surface;
|
|
|
|
vk_swapchain_desc.minImageCount = image_count;
|
|
|
|
vk_swapchain_desc.imageFormat = vk_format;
|
|
|
|
vk_swapchain_desc.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
|
|
|
|
vk_swapchain_desc.imageExtent.width = width;
|
|
|
|
vk_swapchain_desc.imageExtent.height = height;
|
|
|
|
vk_swapchain_desc.imageArrayLayers = 1;
|
|
|
|
vk_swapchain_desc.imageUsage = usage;
|
|
|
|
vk_swapchain_desc.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
|
|
|
vk_swapchain_desc.queueFamilyIndexCount = 0;
|
|
|
|
vk_swapchain_desc.pQueueFamilyIndices = NULL;
|
|
|
|
vk_swapchain_desc.preTransform = surface_caps.currentTransform;
|
|
|
|
vk_swapchain_desc.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
|
|
|
vk_swapchain_desc.presentMode = vk_present_mode;
|
|
|
|
vk_swapchain_desc.clipped = VK_TRUE;
|
|
|
|
vk_swapchain_desc.oldSwapchain = VK_NULL_HANDLE;
|
|
|
|
if ((vr = VK_CALL(vkCreateSwapchainKHR(device_vk->vk_device, &vk_swapchain_desc, NULL, &vk_swapchain))) < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to create Vulkan swapchain, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
swapchain_vk->vk_swapchain = vk_swapchain;
|
|
|
|
|
|
|
|
if (!wined3d_swapchain_vk_create_vulkan_swapchain_images(swapchain_vk, vk_swapchain))
|
|
|
|
{
|
|
|
|
VK_CALL(vkDestroySwapchainKHR(device_vk->vk_device, vk_swapchain, NULL));
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
VK_CALL(vkDestroySurfaceKHR(vk_info->instance, vk_surface, NULL));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT wined3d_swapchain_vk_recreate(struct wined3d_swapchain_vk *swapchain_vk)
|
|
|
|
{
|
|
|
|
TRACE("swapchain_vk %p.\n", swapchain_vk);
|
|
|
|
|
|
|
|
wined3d_swapchain_vk_destroy_vulkan_swapchain(swapchain_vk);
|
|
|
|
|
|
|
|
return wined3d_swapchain_vk_create_vulkan_swapchain(swapchain_vk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_swapchain_vk_set_swap_interval(struct wined3d_swapchain_vk *swapchain_vk,
|
|
|
|
unsigned int swap_interval)
|
|
|
|
{
|
|
|
|
if (swap_interval > 1)
|
|
|
|
{
|
|
|
|
if (swap_interval <= 4)
|
|
|
|
FIXME("Unsupported swap interval %u.\n", swap_interval);
|
|
|
|
swap_interval = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain_vk->s.swap_interval == swap_interval)
|
|
|
|
return;
|
|
|
|
|
|
|
|
swapchain_vk->s.swap_interval = swap_interval;
|
|
|
|
wined3d_swapchain_vk_recreate(swapchain_vk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_swapchain_vk_blit(struct wined3d_swapchain_vk *swapchain_vk,
|
|
|
|
struct wined3d_context_vk *context_vk, const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval)
|
|
|
|
{
|
|
|
|
struct wined3d_texture_vk *back_buffer_vk = wined3d_texture_vk(swapchain_vk->s.back_buffers[0]);
|
|
|
|
struct wined3d_device_vk *device_vk = wined3d_device_vk(swapchain_vk->s.device);
|
|
|
|
const struct wined3d_swapchain_desc *desc = &swapchain_vk->s.state.desc;
|
|
|
|
const struct wined3d_vk_info *vk_info = context_vk->vk_info;
|
|
|
|
VkCommandBuffer vk_command_buffer;
|
|
|
|
VkPresentInfoKHR present_desc;
|
|
|
|
unsigned int present_idx;
|
|
|
|
VkImageLayout vk_layout;
|
|
|
|
uint32_t image_idx;
|
|
|
|
VkImageBlit blit;
|
|
|
|
VkResult vr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
static const VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
|
|
|
|
wined3d_swapchain_vk_set_swap_interval(swapchain_vk, swap_interval);
|
|
|
|
|
|
|
|
present_idx = swapchain_vk->current++ % swapchain_vk->image_count;
|
|
|
|
wined3d_context_vk_wait_command_buffer(context_vk, swapchain_vk->vk_semaphores[present_idx].command_buffer_id);
|
|
|
|
vr = VK_CALL(vkAcquireNextImageKHR(device_vk->vk_device, swapchain_vk->vk_swapchain, UINT64_MAX,
|
|
|
|
swapchain_vk->vk_semaphores[present_idx].available, VK_NULL_HANDLE, &image_idx));
|
|
|
|
if (vr == VK_ERROR_OUT_OF_DATE_KHR)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = wined3d_swapchain_vk_recreate(swapchain_vk)))
|
|
|
|
{
|
|
|
|
ERR("Failed to recreate swapchain, hr %#x.\n", hr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vr = VK_CALL(vkAcquireNextImageKHR(device_vk->vk_device, swapchain_vk->vk_swapchain, UINT64_MAX,
|
|
|
|
swapchain_vk->vk_semaphores[present_idx].available, VK_NULL_HANDLE, &image_idx));
|
|
|
|
}
|
|
|
|
if (vr < 0)
|
|
|
|
{
|
|
|
|
ERR("Failed to acquire next Vulkan image, vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
vk_command_buffer = wined3d_context_vk_get_command_buffer(context_vk);
|
|
|
|
|
|
|
|
wined3d_context_vk_end_current_render_pass(context_vk);
|
|
|
|
|
|
|
|
wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
|
|
|
|
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
vk_access_mask_from_bind_flags(back_buffer_vk->t.resource.bind_flags),
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
back_buffer_vk->layout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
|
|
|
back_buffer_vk->vk_image, VK_IMAGE_ASPECT_COLOR_BIT);
|
|
|
|
|
|
|
|
wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
|
|
|
|
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
0, VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
swapchain_vk->vk_images[image_idx], VK_IMAGE_ASPECT_COLOR_BIT);
|
|
|
|
|
|
|
|
blit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
|
blit.srcSubresource.mipLevel = 0;
|
|
|
|
blit.srcSubresource.baseArrayLayer = 0;
|
|
|
|
blit.srcSubresource.layerCount = 1;
|
|
|
|
blit.srcOffsets[0].x = src_rect->left;
|
|
|
|
blit.srcOffsets[0].y = src_rect->top;
|
|
|
|
blit.srcOffsets[0].z = 0;
|
|
|
|
blit.srcOffsets[1].x = src_rect->right;
|
|
|
|
blit.srcOffsets[1].y = src_rect->bottom;
|
|
|
|
blit.srcOffsets[1].z = 1;
|
|
|
|
blit.dstSubresource = blit.srcSubresource;
|
|
|
|
blit.dstOffsets[0].x = dst_rect->left;
|
|
|
|
blit.dstOffsets[0].y = dst_rect->top;
|
|
|
|
blit.dstOffsets[0].z = 0;
|
|
|
|
blit.dstOffsets[1].x = dst_rect->right;
|
|
|
|
blit.dstOffsets[1].y = dst_rect->bottom;
|
|
|
|
blit.dstOffsets[1].z = 1;
|
|
|
|
VK_CALL(vkCmdBlitImage(vk_command_buffer,
|
|
|
|
back_buffer_vk->vk_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
|
|
|
swapchain_vk->vk_images[image_idx], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
|
|
1, &blit, VK_FILTER_NEAREST));
|
|
|
|
|
2020-06-05 13:49:30 +02:00
|
|
|
wined3d_context_vk_reference_texture(context_vk, back_buffer_vk);
|
2020-05-29 18:03:35 +02:00
|
|
|
wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT, 0,
|
|
|
|
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
|
|
|
swapchain_vk->vk_images[image_idx], VK_IMAGE_ASPECT_COLOR_BIT);
|
|
|
|
|
|
|
|
if (desc->swap_effect == WINED3D_SWAP_EFFECT_DISCARD || desc->swap_effect == WINED3D_SWAP_EFFECT_FLIP_DISCARD)
|
|
|
|
vk_layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
else
|
|
|
|
vk_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
|
|
|
|
wined3d_context_vk_image_barrier(context_vk, vk_command_buffer,
|
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
|
|
|
|
VK_ACCESS_TRANSFER_READ_BIT,
|
|
|
|
vk_access_mask_from_bind_flags(back_buffer_vk->t.resource.bind_flags),
|
|
|
|
vk_layout, back_buffer_vk->layout,
|
|
|
|
back_buffer_vk->vk_image, VK_IMAGE_ASPECT_COLOR_BIT);
|
|
|
|
|
|
|
|
swapchain_vk->vk_semaphores[present_idx].command_buffer_id = context_vk->current_command_buffer.id;
|
|
|
|
wined3d_context_vk_submit_command_buffer(context_vk,
|
|
|
|
1, &swapchain_vk->vk_semaphores[present_idx].available, &wait_stage,
|
|
|
|
1, &swapchain_vk->vk_semaphores[present_idx].presentable);
|
|
|
|
|
|
|
|
present_desc.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
|
|
|
present_desc.pNext = NULL;
|
|
|
|
present_desc.waitSemaphoreCount = 1;
|
|
|
|
present_desc.pWaitSemaphores = &swapchain_vk->vk_semaphores[present_idx].presentable;
|
|
|
|
present_desc.swapchainCount = 1;
|
|
|
|
present_desc.pSwapchains = &swapchain_vk->vk_swapchain;
|
|
|
|
present_desc.pImageIndices = &image_idx;
|
|
|
|
present_desc.pResults = NULL;
|
|
|
|
if ((vr = VK_CALL(vkQueuePresentKHR(device_vk->vk_queue, &present_desc))))
|
|
|
|
ERR("Present returned vr %s.\n", wined3d_debug_vkresult(vr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wined3d_swapchain_vk_rotate(struct wined3d_swapchain *swapchain, struct wined3d_context_vk *context_vk)
|
|
|
|
{
|
|
|
|
struct wined3d_texture_sub_resource *sub_resource;
|
|
|
|
struct wined3d_texture_vk *texture, *texture_prev;
|
|
|
|
struct wined3d_allocator_block *memory0;
|
|
|
|
VkDescriptorImageInfo vk_info0;
|
|
|
|
VkDeviceMemory vk_memory0;
|
|
|
|
VkImageLayout vk_layout0;
|
|
|
|
VkImage vk_image0;
|
|
|
|
DWORD locations0;
|
|
|
|
unsigned int i;
|
|
|
|
uint64_t id0;
|
|
|
|
|
|
|
|
static const DWORD supported_locations = WINED3D_LOCATION_TEXTURE_RGB | WINED3D_LOCATION_RB_MULTISAMPLE;
|
|
|
|
|
|
|
|
if (swapchain->state.desc.backbuffer_count < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
texture_prev = wined3d_texture_vk(swapchain->back_buffers[0]);
|
|
|
|
|
|
|
|
/* Back buffer 0 is already in the draw binding. */
|
|
|
|
vk_image0 = texture_prev->vk_image;
|
|
|
|
memory0 = texture_prev->memory;
|
|
|
|
vk_memory0 = texture_prev->vk_memory;
|
|
|
|
vk_layout0 = texture_prev->layout;
|
|
|
|
id0 = texture_prev->command_buffer_id;
|
|
|
|
vk_info0 = texture_prev->default_image_info;
|
|
|
|
locations0 = texture_prev->t.sub_resources[0].locations;
|
|
|
|
|
|
|
|
for (i = 1; i < swapchain->state.desc.backbuffer_count; ++i)
|
|
|
|
{
|
|
|
|
texture = wined3d_texture_vk(swapchain->back_buffers[i]);
|
|
|
|
sub_resource = &texture->t.sub_resources[0];
|
|
|
|
|
|
|
|
if (!(sub_resource->locations & supported_locations))
|
|
|
|
wined3d_texture_load_location(&texture->t, 0, &context_vk->c, texture->t.resource.draw_binding);
|
|
|
|
|
|
|
|
texture_prev->vk_image = texture->vk_image;
|
|
|
|
texture_prev->memory = texture->memory;
|
|
|
|
texture_prev->vk_memory = texture->vk_memory;
|
|
|
|
texture_prev->layout = texture->layout;
|
|
|
|
texture_prev->command_buffer_id = texture->command_buffer_id;
|
|
|
|
texture_prev->default_image_info = texture->default_image_info;
|
|
|
|
|
|
|
|
wined3d_texture_validate_location(&texture_prev->t, 0, sub_resource->locations & supported_locations);
|
|
|
|
wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(sub_resource->locations & supported_locations));
|
|
|
|
|
|
|
|
texture_prev = texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
texture_prev->vk_image = vk_image0;
|
|
|
|
texture_prev->memory = memory0;
|
|
|
|
texture_prev->vk_memory = vk_memory0;
|
|
|
|
texture_prev->layout = vk_layout0;
|
|
|
|
texture_prev->command_buffer_id = id0;
|
|
|
|
texture_prev->default_image_info = vk_info0;
|
|
|
|
|
|
|
|
wined3d_texture_validate_location(&texture_prev->t, 0, locations0 & supported_locations);
|
|
|
|
wined3d_texture_invalidate_location(&texture_prev->t, 0, ~(locations0 & supported_locations));
|
|
|
|
|
|
|
|
device_invalidate_state(swapchain->device, STATE_FRAMEBUFFER);
|
|
|
|
}
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
static void swapchain_vk_present(struct wined3d_swapchain *swapchain, const RECT *src_rect,
|
|
|
|
const RECT *dst_rect, unsigned int swap_interval, uint32_t flags)
|
|
|
|
{
|
2020-05-29 18:03:35 +02:00
|
|
|
struct wined3d_swapchain_vk *swapchain_vk = wined3d_swapchain_vk(swapchain);
|
|
|
|
struct wined3d_texture *back_buffer = swapchain->back_buffers[0];
|
|
|
|
struct wined3d_context_vk *context_vk;
|
|
|
|
|
|
|
|
context_vk = wined3d_context_vk(context_acquire(swapchain->device, back_buffer, 0));
|
|
|
|
|
|
|
|
wined3d_texture_load_location(back_buffer, 0, &context_vk->c, back_buffer->resource.draw_binding);
|
|
|
|
|
|
|
|
if (swapchain_vk->vk_swapchain)
|
|
|
|
wined3d_swapchain_vk_blit(swapchain_vk, context_vk, src_rect, dst_rect, swap_interval);
|
|
|
|
|
|
|
|
wined3d_swapchain_vk_rotate(swapchain, context_vk);
|
|
|
|
|
|
|
|
wined3d_texture_validate_location(swapchain->front_buffer, 0, WINED3D_LOCATION_DRAWABLE);
|
|
|
|
wined3d_texture_invalidate_location(swapchain->front_buffer, 0, ~WINED3D_LOCATION_DRAWABLE);
|
|
|
|
|
|
|
|
TRACE("Starting new frame.\n");
|
|
|
|
|
|
|
|
context_release(&context_vk->c);
|
2019-08-08 00:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_swapchain_ops swapchain_vk_ops =
|
|
|
|
{
|
|
|
|
swapchain_vk_present,
|
|
|
|
swapchain_frontbuffer_updated,
|
2005-06-23 13:05:24 +02:00
|
|
|
};
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2016-03-01 19:31:49 +01:00
|
|
|
static void swapchain_gdi_frontbuffer_updated(struct wined3d_swapchain *swapchain)
|
2011-04-07 18:45:58 +02:00
|
|
|
{
|
2018-03-15 09:08:39 +01:00
|
|
|
struct wined3d_dc_info *front;
|
2011-04-07 18:45:58 +02:00
|
|
|
POINT offset = {0, 0};
|
|
|
|
HDC src_dc, dst_dc;
|
|
|
|
RECT draw_rect;
|
|
|
|
HWND window;
|
|
|
|
|
2016-03-01 19:31:49 +01:00
|
|
|
TRACE("swapchain %p.\n", swapchain);
|
2011-04-07 18:45:58 +02:00
|
|
|
|
2018-03-15 09:08:40 +01:00
|
|
|
front = &swapchain->front_buffer->dc_info[0];
|
2014-06-28 10:49:32 +02:00
|
|
|
if (swapchain->palette)
|
2016-04-14 19:32:46 +02:00
|
|
|
wined3d_palette_apply_to_dc(swapchain->palette, front->dc);
|
2014-06-28 10:49:32 +02:00
|
|
|
|
2018-03-14 09:09:14 +01:00
|
|
|
if (swapchain->front_buffer->resource.map_count)
|
2011-11-13 19:52:25 +01:00
|
|
|
ERR("Trying to blit a mapped surface.\n");
|
|
|
|
|
2011-04-07 18:45:58 +02:00
|
|
|
TRACE("Copying surface %p to screen.\n", front);
|
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
src_dc = front->dc;
|
2011-04-07 18:45:58 +02:00
|
|
|
window = swapchain->win_handle;
|
|
|
|
dst_dc = GetDCEx(window, 0, DCX_CLIPSIBLINGS | DCX_CACHE);
|
|
|
|
|
|
|
|
/* Front buffer coordinates are screen coordinates. Map them to the
|
|
|
|
* destination window if not fullscreened. */
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.windowed)
|
2011-04-07 18:45:58 +02:00
|
|
|
ClientToScreen(window, &offset);
|
|
|
|
|
|
|
|
TRACE("offset %s.\n", wine_dbgstr_point(&offset));
|
|
|
|
|
2016-06-29 09:58:26 +02:00
|
|
|
SetRect(&draw_rect, 0, 0, swapchain->front_buffer->resource.width,
|
|
|
|
swapchain->front_buffer->resource.height);
|
2016-03-01 19:31:49 +01:00
|
|
|
IntersectRect(&draw_rect, &draw_rect, &swapchain->front_buffer_update);
|
2011-04-07 18:45:58 +02:00
|
|
|
|
|
|
|
BitBlt(dst_dc, draw_rect.left - offset.x, draw_rect.top - offset.y,
|
|
|
|
draw_rect.right - draw_rect.left, draw_rect.bottom - draw_rect.top,
|
|
|
|
src_dc, draw_rect.left, draw_rect.top, SRCCOPY);
|
|
|
|
ReleaseDC(window, dst_dc);
|
2016-03-01 19:31:49 +01:00
|
|
|
|
|
|
|
SetRectEmpty(&swapchain->front_buffer_update);
|
2011-04-07 18:45:58 +02:00
|
|
|
}
|
|
|
|
|
2016-03-17 16:30:03 +01:00
|
|
|
static void swapchain_gdi_present(struct wined3d_swapchain *swapchain,
|
2019-03-17 18:51:04 +01:00
|
|
|
const RECT *src_rect, const RECT *dst_rect, unsigned int swap_interval, DWORD flags)
|
2011-04-07 18:45:58 +02:00
|
|
|
{
|
2018-03-15 09:08:39 +01:00
|
|
|
struct wined3d_dc_info *front, *back;
|
2016-04-14 19:32:46 +02:00
|
|
|
HBITMAP bitmap;
|
|
|
|
void *data;
|
|
|
|
HDC dc;
|
2011-04-07 18:45:58 +02:00
|
|
|
|
2018-03-15 09:08:40 +01:00
|
|
|
front = &swapchain->front_buffer->dc_info[0];
|
|
|
|
back = &swapchain->back_buffers[0]->dc_info[0];
|
2011-04-07 18:45:58 +02:00
|
|
|
|
|
|
|
/* Flip the surface data. */
|
2016-04-14 19:32:46 +02:00
|
|
|
dc = front->dc;
|
|
|
|
bitmap = front->bitmap;
|
2018-03-14 09:09:14 +01:00
|
|
|
data = swapchain->front_buffer->resource.heap_memory;
|
2011-04-07 18:45:58 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
front->dc = back->dc;
|
|
|
|
front->bitmap = back->bitmap;
|
2018-03-14 09:09:14 +01:00
|
|
|
swapchain->front_buffer->resource.heap_memory = swapchain->back_buffers[0]->resource.heap_memory;
|
2011-04-07 18:45:58 +02:00
|
|
|
|
2016-04-14 19:32:46 +02:00
|
|
|
back->dc = dc;
|
|
|
|
back->bitmap = bitmap;
|
2018-03-14 09:09:14 +01:00
|
|
|
swapchain->back_buffers[0]->resource.heap_memory = data;
|
2011-04-07 18:45:58 +02:00
|
|
|
|
2016-03-01 19:31:49 +01:00
|
|
|
SetRect(&swapchain->front_buffer_update, 0, 0,
|
|
|
|
swapchain->front_buffer->resource.width,
|
|
|
|
swapchain->front_buffer->resource.height);
|
|
|
|
swapchain_gdi_frontbuffer_updated(swapchain);
|
2011-04-07 18:45:58 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
static const struct wined3d_swapchain_ops swapchain_no3d_ops =
|
2011-04-07 18:45:58 +02:00
|
|
|
{
|
2011-04-13 19:14:30 +02:00
|
|
|
swapchain_gdi_present,
|
2016-03-01 19:31:49 +01:00
|
|
|
swapchain_gdi_frontbuffer_updated,
|
2011-04-07 18:45:58 +02:00
|
|
|
};
|
|
|
|
|
2015-08-07 10:01:33 +02:00
|
|
|
static void swapchain_update_render_to_fbo(struct wined3d_swapchain *swapchain)
|
2011-08-22 21:02:47 +02:00
|
|
|
{
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
|
|
|
|
return;
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (!swapchain->state.desc.backbuffer_count)
|
2011-08-22 21:02:47 +02:00
|
|
|
{
|
|
|
|
TRACE("Single buffered rendering.\n");
|
|
|
|
swapchain->render_to_fbo = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Rendering to FBO.\n");
|
|
|
|
swapchain->render_to_fbo = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-03-15 16:55:08 +01:00
|
|
|
static void wined3d_swapchain_apply_sample_count_override(const struct wined3d_swapchain *swapchain,
|
|
|
|
enum wined3d_format_id format_id, enum wined3d_multisample_type *type, DWORD *quality)
|
|
|
|
{
|
2018-08-23 14:34:03 +02:00
|
|
|
const struct wined3d_adapter *adapter;
|
2016-03-15 16:55:08 +01:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
|
|
|
const struct wined3d_format *format;
|
|
|
|
enum wined3d_multisample_type t;
|
|
|
|
|
|
|
|
if (wined3d_settings.sample_count == ~0u)
|
|
|
|
return;
|
|
|
|
|
2018-08-23 14:34:03 +02:00
|
|
|
adapter = swapchain->device->adapter;
|
|
|
|
gl_info = &adapter->gl_info;
|
2018-10-31 10:31:50 +01:00
|
|
|
if (!(format = wined3d_get_format(adapter, format_id, WINED3D_BIND_RENDER_TARGET)))
|
2016-03-15 16:55:08 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ((t = min(wined3d_settings.sample_count, gl_info->limits.samples)))
|
|
|
|
while (!(format->multisample_types & 1u << (t - 1)))
|
|
|
|
++t;
|
|
|
|
TRACE("Using sample count %u.\n", t);
|
|
|
|
*type = t;
|
|
|
|
*quality = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:15:01 +02:00
|
|
|
void swapchain_set_max_frame_latency(struct wined3d_swapchain *swapchain, const struct wined3d_device *device)
|
|
|
|
{
|
|
|
|
/* Subtract 1 for the implicit OpenGL latency. */
|
|
|
|
swapchain->max_frame_latency = device->max_frame_latency >= 2 ? device->max_frame_latency - 1 : 1;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:29:49 +02:00
|
|
|
static enum wined3d_format_id adapter_format_from_backbuffer_format(const struct wined3d_adapter *adapter,
|
2019-03-14 16:30:12 +01:00
|
|
|
enum wined3d_format_id format_id)
|
|
|
|
{
|
|
|
|
const struct wined3d_format *backbuffer_format;
|
|
|
|
|
|
|
|
backbuffer_format = wined3d_get_format(adapter, format_id, WINED3D_BIND_RENDER_TARGET);
|
|
|
|
return pixelformat_for_depth(backbuffer_format->byte_count * CHAR_BIT);
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:29:49 +02:00
|
|
|
static HRESULT wined3d_swapchain_state_init(struct wined3d_swapchain_state *state,
|
2020-10-09 11:56:53 +02:00
|
|
|
const struct wined3d_swapchain_desc *desc, HWND window, struct wined3d *wined3d,
|
|
|
|
struct wined3d_swapchain_state_parent *parent)
|
2019-07-31 22:29:49 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
state->desc = *desc;
|
|
|
|
|
2020-05-12 14:50:12 +02:00
|
|
|
if (FAILED(hr = wined3d_output_get_display_mode(desc->output, &state->original_mode, NULL)))
|
2019-07-31 22:29:49 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get current display mode, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!desc->windowed)
|
|
|
|
{
|
|
|
|
if (desc->flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
|
|
|
|
{
|
|
|
|
state->d3d_mode.width = desc->backbuffer_width;
|
|
|
|
state->d3d_mode.height = desc->backbuffer_height;
|
2020-05-12 14:50:12 +02:00
|
|
|
state->d3d_mode.format_id = adapter_format_from_backbuffer_format(desc->output->adapter,
|
2020-03-05 16:03:53 +01:00
|
|
|
desc->backbuffer_format);
|
2019-07-31 22:29:49 +02:00
|
|
|
state->d3d_mode.refresh_rate = desc->refresh_rate;
|
|
|
|
state->d3d_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
state->d3d_mode = state->original_mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GetWindowRect(window, &state->original_window_rect);
|
2020-10-28 07:38:44 +01:00
|
|
|
state->wined3d = wined3d;
|
2019-07-31 22:29:49 +02:00
|
|
|
state->device_window = window;
|
2020-10-09 11:56:53 +02:00
|
|
|
state->parent = parent;
|
2019-07-31 22:29:49 +02:00
|
|
|
|
2020-10-09 11:56:42 +02:00
|
|
|
if (desc->flags & WINED3D_SWAPCHAIN_REGISTER_STATE)
|
2020-10-28 07:38:44 +01:00
|
|
|
wined3d_swapchain_state_register(state);
|
2020-10-09 11:56:42 +02:00
|
|
|
|
2019-07-31 22:29:49 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
static HRESULT wined3d_swapchain_init(struct wined3d_swapchain *swapchain, struct wined3d_device *device,
|
2020-10-09 11:56:53 +02:00
|
|
|
struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops,
|
2019-08-08 00:47:04 +02:00
|
|
|
const struct wined3d_swapchain_ops *swapchain_ops)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2015-09-03 20:56:26 +02:00
|
|
|
struct wined3d_resource_desc texture_desc;
|
2020-05-07 09:52:12 +02:00
|
|
|
struct wined3d_output_desc output_desc;
|
2009-12-10 21:41:54 +01:00
|
|
|
BOOL displaymode_set = FALSE;
|
2017-02-09 05:51:56 +01:00
|
|
|
DWORD texture_flags = 0;
|
2020-05-07 09:52:12 +02:00
|
|
|
HRESULT hr = E_FAIL;
|
2009-12-10 21:41:54 +01:00
|
|
|
RECT client_rect;
|
2018-03-23 13:44:35 +01:00
|
|
|
unsigned int i;
|
2009-12-10 21:41:54 +01:00
|
|
|
HWND window;
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (desc->backbuffer_count > 1)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
FIXME("The application requested more than one back buffer, this is not properly supported.\n"
|
|
|
|
"Please configure the application to use double buffering (1 back buffer) if possible.\n");
|
|
|
|
}
|
|
|
|
|
2018-02-15 07:05:15 +01:00
|
|
|
if (desc->swap_effect != WINED3D_SWAP_EFFECT_DISCARD
|
|
|
|
&& desc->swap_effect != WINED3D_SWAP_EFFECT_SEQUENTIAL
|
|
|
|
&& desc->swap_effect != WINED3D_SWAP_EFFECT_COPY)
|
|
|
|
FIXME("Unimplemented swap effect %#x.\n", desc->swap_effect);
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
window = desc->device_window ? desc->device_window : device->create_parms.focus_window;
|
2020-10-09 11:56:53 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_state_init(&swapchain->state, desc, window, device->wined3d, state_parent)))
|
2020-05-07 09:51:56 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to initialise swapchain state, hr %#x.\n", hr);
|
2020-10-12 10:41:01 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
return hr;
|
2020-05-07 09:51:56 +02:00
|
|
|
}
|
2009-12-10 21:41:54 +01:00
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
swapchain->swapchain_ops = swapchain_ops;
|
2009-12-10 21:41:54 +01:00
|
|
|
swapchain->device = device;
|
|
|
|
swapchain->parent = parent;
|
2011-04-07 18:46:01 +02:00
|
|
|
swapchain->parent_ops = parent_ops;
|
2009-12-10 21:41:54 +01:00
|
|
|
swapchain->ref = 1;
|
|
|
|
swapchain->win_handle = window;
|
2018-03-23 13:44:35 +01:00
|
|
|
swapchain->swap_interval = WINED3D_SWAP_INTERVAL_DEFAULT;
|
2018-04-30 20:15:01 +02:00
|
|
|
swapchain_set_max_frame_latency(swapchain, device);
|
2009-12-10 21:41:54 +01:00
|
|
|
|
|
|
|
GetClientRect(window, &client_rect);
|
2016-08-03 09:41:38 +02:00
|
|
|
if (desc->windowed)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2018-05-17 15:46:54 +02:00
|
|
|
TRACE("Client rect %s.\n", wine_dbgstr_rect(&client_rect));
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!desc->backbuffer_width)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2018-05-17 15:46:54 +02:00
|
|
|
desc->backbuffer_width = client_rect.right ? client_rect.right : 8;
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("Updating width to %u.\n", desc->backbuffer_width);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!desc->backbuffer_height)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2018-05-17 15:46:54 +02:00
|
|
|
desc->backbuffer_height = client_rect.bottom ? client_rect.bottom : 8;
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("Updating height to %u.\n", desc->backbuffer_height);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (desc->backbuffer_format == WINED3DFMT_UNKNOWN)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2019-07-31 22:29:49 +02:00
|
|
|
desc->backbuffer_format = swapchain->state.original_mode.format_id;
|
|
|
|
TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->state.original_mode.format_id));
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-29 13:30:52 +02:00
|
|
|
else
|
|
|
|
{
|
2020-05-12 14:49:31 +02:00
|
|
|
if (FAILED(hr = wined3d_output_get_desc(desc->output, &output_desc)))
|
2020-05-07 09:52:12 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get output description, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
wined3d_swapchain_state_setup_fullscreen(&swapchain->state, window,
|
|
|
|
output_desc.desktop_rect.left, output_desc.desktop_rect.top, desc->backbuffer_width,
|
|
|
|
desc->backbuffer_height);
|
2019-07-29 13:30:52 +02:00
|
|
|
}
|
2019-07-29 13:30:55 +02:00
|
|
|
swapchain->state.desc = *desc;
|
|
|
|
wined3d_swapchain_apply_sample_count_override(swapchain, swapchain->state.desc.backbuffer_format,
|
|
|
|
&swapchain->state.desc.multisample_type, &swapchain->state.desc.multisample_quality);
|
2011-08-22 21:02:47 +02:00
|
|
|
swapchain_update_render_to_fbo(swapchain);
|
2009-12-10 21:41:54 +01:00
|
|
|
|
|
|
|
TRACE("Creating front buffer.\n");
|
2013-06-04 09:57:08 +02:00
|
|
|
|
2016-01-27 00:06:23 +01:00
|
|
|
texture_desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
|
2019-07-29 13:30:55 +02:00
|
|
|
texture_desc.format = swapchain->state.desc.backbuffer_format;
|
|
|
|
texture_desc.multisample_type = swapchain->state.desc.multisample_type;
|
|
|
|
texture_desc.multisample_quality = swapchain->state.desc.multisample_quality;
|
2015-09-03 20:56:26 +02:00
|
|
|
texture_desc.usage = 0;
|
2018-09-27 17:30:33 +02:00
|
|
|
if (device->wined3d->flags & WINED3D_NO3D)
|
|
|
|
texture_desc.usage |= WINED3DUSAGE_OWNDC;
|
2018-10-31 10:31:47 +01:00
|
|
|
texture_desc.bind_flags = 0;
|
2020-06-02 01:17:00 +02:00
|
|
|
if (device->wined3d->flags & WINED3D_NO3D)
|
|
|
|
texture_desc.access = WINED3D_RESOURCE_ACCESS_CPU;
|
|
|
|
else
|
|
|
|
texture_desc.access = WINED3D_RESOURCE_ACCESS_GPU;
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.flags & WINED3D_SWAPCHAIN_LOCKABLE_BACKBUFFER)
|
2018-11-08 18:59:02 +01:00
|
|
|
texture_desc.access |= WINED3D_RESOURCE_ACCESS_MAP_R | WINED3D_RESOURCE_ACCESS_MAP_W;
|
2019-07-29 13:30:55 +02:00
|
|
|
texture_desc.width = swapchain->state.desc.backbuffer_width;
|
|
|
|
texture_desc.height = swapchain->state.desc.backbuffer_height;
|
2015-09-03 20:56:26 +02:00
|
|
|
texture_desc.depth = 1;
|
|
|
|
texture_desc.size = 0;
|
2013-06-04 09:57:08 +02:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.flags & WINED3D_SWAPCHAIN_GDI_COMPATIBLE)
|
2017-02-09 05:51:56 +01:00
|
|
|
texture_flags |= WINED3D_TEXTURE_CREATE_GET_DC;
|
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
|
2017-02-09 05:51:56 +01:00
|
|
|
parent, &texture_desc, texture_flags, &swapchain->front_buffer)))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create front buffer, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
wined3d_texture_set_swapchain(swapchain->front_buffer, swapchain);
|
2013-01-16 08:51:49 +01:00
|
|
|
if (!(device->wined3d->flags & WINED3D_NO3D))
|
2013-09-10 09:32:34 +02:00
|
|
|
{
|
2016-03-29 16:45:36 +02:00
|
|
|
wined3d_texture_validate_location(swapchain->front_buffer, 0, WINED3D_LOCATION_DRAWABLE);
|
2016-03-30 21:30:19 +02:00
|
|
|
wined3d_texture_invalidate_location(swapchain->front_buffer, 0, ~WINED3D_LOCATION_DRAWABLE);
|
2013-09-10 09:32:34 +02:00
|
|
|
}
|
2009-12-10 21:41:54 +01:00
|
|
|
|
|
|
|
/* MSDN says we're only allowed a single fullscreen swapchain per device,
|
|
|
|
* so we should really check to see if there is a fullscreen swapchain
|
|
|
|
* already. Does a single head count as full screen? */
|
2019-07-31 22:29:49 +02:00
|
|
|
if (!desc->windowed && desc->flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2019-07-31 22:29:49 +02:00
|
|
|
/* Change the display settings */
|
2020-05-12 14:49:31 +02:00
|
|
|
if (FAILED(hr = wined3d_output_set_display_mode(desc->output,
|
2020-03-06 14:16:16 +01:00
|
|
|
&swapchain->state.d3d_mode)))
|
2016-08-03 09:41:38 +02:00
|
|
|
{
|
2019-07-31 22:29:49 +02:00
|
|
|
WARN("Failed to set display mode, hr %#x.\n", hr);
|
|
|
|
goto err;
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
2019-07-31 22:29:49 +02:00
|
|
|
displaymode_set = TRUE;
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (swapchain->state.desc.backbuffer_count > 0)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
if (!(swapchain->back_buffers = heap_calloc(swapchain->state.desc.backbuffer_count,
|
2016-05-23 18:06:27 +02:00
|
|
|
sizeof(*swapchain->back_buffers))))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate backbuffer array memory.\n");
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
texture_desc.bind_flags = swapchain->state.desc.backbuffer_bind_flags;
|
2018-10-31 10:31:48 +01:00
|
|
|
texture_desc.usage = 0;
|
2018-09-27 17:30:33 +02:00
|
|
|
if (device->wined3d->flags & WINED3D_NO3D)
|
|
|
|
texture_desc.usage |= WINED3DUSAGE_OWNDC;
|
2019-07-29 13:30:55 +02:00
|
|
|
for (i = 0; i < swapchain->state.desc.backbuffer_count; ++i)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
TRACE("Creating back buffer %u.\n", i);
|
2015-09-03 20:56:26 +02:00
|
|
|
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
|
2017-02-09 05:51:56 +01:00
|
|
|
parent, &texture_desc, texture_flags, &swapchain->back_buffers[i])))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
|
2019-07-29 13:30:55 +02:00
|
|
|
swapchain->state.desc.backbuffer_count = i;
|
2009-12-10 21:41:54 +01:00
|
|
|
goto err;
|
|
|
|
}
|
2014-08-20 13:20:03 +02:00
|
|
|
wined3d_texture_set_swapchain(swapchain->back_buffers[i], swapchain);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */
|
2019-07-03 13:49:07 +02:00
|
|
|
if (desc->enable_auto_depth_stencil)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
TRACE("Creating depth/stencil buffer.\n");
|
2014-08-22 12:32:01 +02:00
|
|
|
if (!device->auto_depth_stencil_view)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2016-12-05 12:04:41 +01:00
|
|
|
struct wined3d_view_desc desc;
|
2015-09-03 20:56:26 +02:00
|
|
|
struct wined3d_texture *ds;
|
2014-08-22 12:32:01 +02:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
texture_desc.format = swapchain->state.desc.auto_depth_stencil_format;
|
2018-11-06 11:12:58 +01:00
|
|
|
texture_desc.usage = 0;
|
2018-10-31 10:31:47 +01:00
|
|
|
texture_desc.bind_flags = WINED3D_BIND_DEPTH_STENCIL;
|
2020-06-02 01:17:00 +02:00
|
|
|
if (device->wined3d->flags & WINED3D_NO3D)
|
|
|
|
texture_desc.access = WINED3D_RESOURCE_ACCESS_CPU;
|
|
|
|
else
|
|
|
|
texture_desc.access = WINED3D_RESOURCE_ACCESS_GPU;
|
2013-06-04 09:57:08 +02:00
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
if (FAILED(hr = device->device_parent->ops->create_swapchain_texture(device->device_parent,
|
2018-11-07 09:01:15 +01:00
|
|
|
device->device_parent, &texture_desc, 0, &ds)))
|
2014-08-22 12:32:01 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to create the auto depth/stencil surface, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
desc.format_id = ds->resource.format->id;
|
2016-12-05 12:04:41 +01:00
|
|
|
desc.flags = 0;
|
2015-09-03 20:56:26 +02:00
|
|
|
desc.u.texture.level_idx = 0;
|
2016-12-05 12:04:41 +01:00
|
|
|
desc.u.texture.level_count = 1;
|
2015-09-03 20:56:26 +02:00
|
|
|
desc.u.texture.layer_idx = 0;
|
|
|
|
desc.u.texture.layer_count = 1;
|
|
|
|
hr = wined3d_rendertarget_view_create(&desc, &ds->resource, NULL, &wined3d_null_parent_ops,
|
|
|
|
&device->auto_depth_stencil_view);
|
|
|
|
wined3d_texture_decref(ds);
|
2014-08-22 12:32:01 +02:00
|
|
|
if (FAILED(hr))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
ERR("Failed to create rendertarget view, hr %#x.\n", hr);
|
2009-12-10 21:41:54 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_get_gamma_ramp(swapchain, &swapchain->orig_gamma);
|
2009-12-10 21:41:54 +01:00
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2009-12-10 21:41:54 +01:00
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (displaymode_set)
|
|
|
|
{
|
2020-11-02 10:44:57 +01:00
|
|
|
if (FAILED(wined3d_restore_display_modes(device->wined3d)))
|
2013-08-20 10:20:09 +02:00
|
|
|
ERR("Failed to restore display mode.\n");
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (swapchain->back_buffers)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
for (i = 0; i < swapchain->state.desc.backbuffer_count; ++i)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2011-04-29 13:03:41 +02:00
|
|
|
if (swapchain->back_buffers[i])
|
2011-06-01 01:38:24 +02:00
|
|
|
{
|
2014-08-20 13:20:03 +02:00
|
|
|
wined3d_texture_set_swapchain(swapchain->back_buffers[i], NULL);
|
|
|
|
wined3d_texture_decref(swapchain->back_buffers[i]);
|
2011-06-01 01:38:24 +02:00
|
|
|
}
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
2018-02-14 07:39:59 +01:00
|
|
|
heap_free(swapchain->back_buffers);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
if (swapchain->front_buffer)
|
2011-06-01 01:38:24 +02:00
|
|
|
{
|
2014-08-20 13:20:02 +02:00
|
|
|
wined3d_texture_set_swapchain(swapchain->front_buffer, NULL);
|
|
|
|
wined3d_texture_decref(swapchain->front_buffer);
|
2011-06-01 01:38:24 +02:00
|
|
|
}
|
2009-12-10 21:41:54 +01:00
|
|
|
|
2020-10-12 10:41:01 +02:00
|
|
|
wined3d_swapchain_state_cleanup(&swapchain->state);
|
2019-08-08 00:47:04 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2009-12-10 21:41:54 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
HRESULT wined3d_swapchain_no3d_init(struct wined3d_swapchain *swapchain_no3d, struct wined3d_device *device,
|
2020-10-09 11:56:53 +02:00
|
|
|
struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2019-08-08 00:47:04 +02:00
|
|
|
{
|
2020-10-09 11:56:53 +02:00
|
|
|
TRACE("swapchain_no3d %p, device %p, desc %p, state_parent %p, parent %p, parent_ops %p.\n",
|
|
|
|
swapchain_no3d, device, desc, state_parent, parent, parent_ops);
|
2019-08-08 00:47:04 +02:00
|
|
|
|
2020-10-09 11:56:53 +02:00
|
|
|
return wined3d_swapchain_init(swapchain_no3d, device, desc, state_parent, parent, parent_ops,
|
|
|
|
&swapchain_no3d_ops);
|
2019-08-08 00:47:04 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:37 +02:00
|
|
|
HRESULT wined3d_swapchain_gl_init(struct wined3d_swapchain_gl *swapchain_gl, struct wined3d_device *device,
|
2020-10-09 11:56:53 +02:00
|
|
|
struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2019-08-08 00:47:04 +02:00
|
|
|
{
|
2019-08-13 10:31:39 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-10-09 11:56:53 +02:00
|
|
|
TRACE("swapchain_gl %p, device %p, desc %p, state_parent %p, parent %p, parent_ops %p.\n",
|
|
|
|
swapchain_gl, device, desc, state_parent, parent, parent_ops);
|
2019-08-08 00:47:04 +02:00
|
|
|
|
2020-10-09 11:56:53 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_init(&swapchain_gl->s, device, desc, state_parent, parent,
|
|
|
|
parent_ops, &swapchain_gl_ops)))
|
2019-08-13 10:31:39 +02:00
|
|
|
{
|
|
|
|
/* Cleanup any context that may have been created for the swapchain. */
|
|
|
|
wined3d_cs_destroy_object(device->cs, wined3d_swapchain_gl_destroy_object, swapchain_gl);
|
|
|
|
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2019-08-08 00:47:04 +02:00
|
|
|
}
|
|
|
|
|
2020-05-29 18:03:35 +02:00
|
|
|
HRESULT wined3d_swapchain_vk_init(struct wined3d_swapchain_vk *swapchain_vk, struct wined3d_device *device,
|
2020-10-09 11:56:53 +02:00
|
|
|
struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops)
|
2019-08-08 00:47:04 +02:00
|
|
|
{
|
2020-05-29 18:03:35 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
TRACE("swapchain_vk %p, device %p, desc %p, parent %p, parent_ops %p.\n",
|
|
|
|
swapchain_vk, device, desc, parent, parent_ops);
|
|
|
|
|
2020-10-09 11:56:53 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_init(&swapchain_vk->s, device, desc, state_parent, parent,
|
|
|
|
parent_ops, &swapchain_vk_ops)))
|
2020-05-29 18:03:35 +02:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (swapchain_vk->s.win_handle == GetDesktopWindow())
|
|
|
|
{
|
|
|
|
WARN("Creating a desktop window swapchain.\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = wined3d_swapchain_vk_create_vulkan_swapchain(swapchain_vk)))
|
|
|
|
{
|
|
|
|
wined3d_swapchain_cleanup(&swapchain_vk->s);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2019-08-08 00:47:04 +02:00
|
|
|
}
|
|
|
|
|
2020-10-09 11:56:53 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device,
|
|
|
|
struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
|
|
|
|
void *parent, const struct wined3d_parent_ops *parent_ops,
|
|
|
|
struct wined3d_swapchain **swapchain)
|
2011-05-10 21:18:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_swapchain *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
if (FAILED(hr = device->adapter->adapter_ops->adapter_create_swapchain(device,
|
2020-10-09 11:56:53 +02:00
|
|
|
desc, state_parent, parent, parent_ops, &object)))
|
2011-05-10 21:18:47 +02:00
|
|
|
return hr;
|
|
|
|
|
2019-04-12 14:50:47 +02:00
|
|
|
if (desc->flags & WINED3D_SWAPCHAIN_IMPLICIT)
|
|
|
|
{
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
if (FAILED(hr = wined3d_device_set_implicit_swapchain(device, object)))
|
|
|
|
{
|
|
|
|
wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
2019-08-08 00:47:04 +02:00
|
|
|
device->adapter->adapter_ops->adapter_destroy_swapchain(object);
|
2019-04-12 14:50:47 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:18:47 +02:00
|
|
|
*swapchain = object;
|
|
|
|
|
2019-08-08 00:47:04 +02:00
|
|
|
return hr;
|
2011-05-10 21:18:47 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
static struct wined3d_context_gl *wined3d_swapchain_gl_create_context(struct wined3d_swapchain_gl *swapchain_gl)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
2019-08-13 10:31:39 +02:00
|
|
|
struct wined3d_device *device = swapchain_gl->s.device;
|
2019-06-05 14:24:07 +02:00
|
|
|
struct wined3d_context_gl *context_gl;
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
TRACE("Creating a new context for swapchain %p, thread %u.\n", swapchain_gl, GetCurrentThreadId());
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2019-06-05 14:24:07 +02:00
|
|
|
wined3d_from_cs(device->cs);
|
|
|
|
|
|
|
|
if (!(context_gl = heap_alloc_zero(sizeof(*context_gl))))
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate context memory.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
if (FAILED(wined3d_context_gl_init(context_gl, swapchain_gl)))
|
2009-10-28 11:00:12 +01:00
|
|
|
{
|
2019-06-05 14:24:07 +02:00
|
|
|
WARN("Failed to initialise context.\n");
|
|
|
|
heap_free(context_gl);
|
2007-06-02 22:21:57 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-06-05 14:24:07 +02:00
|
|
|
|
|
|
|
if (!device_context_add(device, &context_gl->c))
|
|
|
|
{
|
|
|
|
ERR("Failed to add the newly created context to the context list.\n");
|
|
|
|
wined3d_context_gl_destroy(context_gl);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created context %p.\n", context_gl);
|
|
|
|
|
|
|
|
context_release(&context_gl->c);
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
if (!wined3d_array_reserve((void **)&swapchain_gl->contexts, &swapchain_gl->contexts_size,
|
|
|
|
swapchain_gl->context_count + 1, sizeof(*swapchain_gl->contexts)))
|
2016-05-23 18:06:27 +02:00
|
|
|
{
|
2019-06-05 14:24:07 +02:00
|
|
|
ERR("Failed to allocate new context array memory.\n");
|
|
|
|
wined3d_context_gl_destroy(context_gl);
|
2007-06-02 22:21:57 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-08-13 10:31:39 +02:00
|
|
|
swapchain_gl->contexts[swapchain_gl->context_count++] = context_gl;
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
return context_gl;
|
2007-06-02 22:21:57 +02:00
|
|
|
}
|
2007-11-30 20:22:33 +01:00
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
void wined3d_swapchain_gl_destroy_contexts(struct wined3d_swapchain_gl *swapchain_gl)
|
2011-06-28 02:26:20 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
for (i = 0; i < swapchain_gl->context_count; ++i)
|
2011-06-28 02:26:20 +02:00
|
|
|
{
|
2019-08-13 10:31:39 +02:00
|
|
|
wined3d_context_gl_destroy(swapchain_gl->contexts[i]);
|
2011-06-28 02:26:20 +02:00
|
|
|
}
|
2019-08-13 10:31:39 +02:00
|
|
|
heap_free(swapchain_gl->contexts);
|
|
|
|
swapchain_gl->contexts_size = 0;
|
|
|
|
swapchain_gl->context_count = 0;
|
|
|
|
swapchain_gl->contexts = NULL;
|
2011-06-28 02:26:20 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
struct wined3d_context_gl *wined3d_swapchain_gl_get_context(struct wined3d_swapchain_gl *swapchain_gl)
|
2011-01-19 19:20:11 +01:00
|
|
|
{
|
|
|
|
DWORD tid = GetCurrentThreadId();
|
|
|
|
unsigned int i;
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
for (i = 0; i < swapchain_gl->context_count; ++i)
|
2011-01-19 19:20:11 +01:00
|
|
|
{
|
2019-08-13 10:31:39 +02:00
|
|
|
if (swapchain_gl->contexts[i]->tid == tid)
|
|
|
|
return swapchain_gl->contexts[i];
|
2011-01-19 19:20:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:39 +02:00
|
|
|
/* Create a new context for the thread. */
|
|
|
|
return wined3d_swapchain_gl_create_context(swapchain_gl);
|
2011-01-19 19:20:11 +01:00
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:38 +02:00
|
|
|
HDC wined3d_swapchain_gl_get_backup_dc(struct wined3d_swapchain_gl *swapchain_gl)
|
2011-07-05 22:30:53 +02:00
|
|
|
{
|
2019-08-13 10:31:38 +02:00
|
|
|
if (!swapchain_gl->backup_dc)
|
2011-07-05 22:30:53 +02:00
|
|
|
{
|
2019-08-13 10:31:38 +02:00
|
|
|
TRACE("Creating the backup window for swapchain %p.\n", swapchain_gl);
|
2011-07-05 22:30:53 +02:00
|
|
|
|
2019-08-13 10:31:38 +02:00
|
|
|
if (!(swapchain_gl->backup_wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
|
2011-07-05 22:30:53 +02:00
|
|
|
WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create a window.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:38 +02:00
|
|
|
if (!(swapchain_gl->backup_dc = GetDC(swapchain_gl->backup_wnd)))
|
2011-07-05 22:30:53 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get a DC.\n");
|
2019-08-13 10:31:38 +02:00
|
|
|
DestroyWindow(swapchain_gl->backup_wnd);
|
|
|
|
swapchain_gl->backup_wnd = NULL;
|
2011-07-05 22:30:53 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 10:31:38 +02:00
|
|
|
return swapchain_gl->backup_dc;
|
2011-07-05 22:30:53 +02:00
|
|
|
}
|
2011-08-23 20:08:08 +02:00
|
|
|
|
|
|
|
void swapchain_update_draw_bindings(struct wined3d_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
wined3d_resource_update_draw_binding(&swapchain->front_buffer->resource);
|
2011-08-23 20:08:08 +02:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
for (i = 0; i < swapchain->state.desc.backbuffer_count; ++i)
|
2011-08-23 20:08:08 +02:00
|
|
|
{
|
2014-08-20 13:20:03 +02:00
|
|
|
wined3d_resource_update_draw_binding(&swapchain->back_buffers[i]->resource);
|
2011-08-23 20:08:08 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-13 20:39:25 +01:00
|
|
|
|
|
|
|
void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activate)
|
|
|
|
{
|
2014-12-04 21:51:49 +01:00
|
|
|
struct wined3d_device *device = swapchain->device;
|
2019-07-31 22:29:46 +02:00
|
|
|
HWND window = swapchain->state.device_window;
|
2020-05-15 09:45:51 +02:00
|
|
|
struct wined3d_output_desc output_desc;
|
2019-08-05 15:55:35 +02:00
|
|
|
unsigned int screensaver_active;
|
2020-03-06 14:16:16 +01:00
|
|
|
struct wined3d_output *output;
|
2019-07-29 13:30:53 +02:00
|
|
|
BOOL focus_messages, filter;
|
2020-05-15 09:45:51 +02:00
|
|
|
HRESULT hr;
|
2014-12-04 21:51:49 +01:00
|
|
|
|
2014-12-01 22:46:48 +01:00
|
|
|
/* This code is not protected by the wined3d mutex, so it may run while
|
|
|
|
* wined3d_device_reset is active. Testing on Windows shows that changing
|
|
|
|
* focus during resets and resetting during focus change events causes
|
|
|
|
* the application to crash with an invalid memory access. */
|
|
|
|
|
2019-07-29 13:30:53 +02:00
|
|
|
if (!(focus_messages = device->wined3d->flags & WINED3D_FOCUS_MESSAGES))
|
|
|
|
filter = wined3d_filter_messages(window, TRUE);
|
2014-12-04 21:51:49 +01:00
|
|
|
|
2014-11-18 21:26:57 +01:00
|
|
|
if (activate)
|
|
|
|
{
|
2019-08-05 15:55:35 +02:00
|
|
|
SystemParametersInfoW(SPI_GETSCREENSAVEACTIVE, 0, &screensaver_active, 0);
|
|
|
|
if ((device->restore_screensaver = !!screensaver_active))
|
|
|
|
SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
|
|
|
|
|
2014-12-04 21:51:49 +01:00
|
|
|
if (!(device->create_parms.flags & WINED3DCREATE_NOWINDOWCHANGES))
|
2014-11-19 20:13:50 +01:00
|
|
|
{
|
|
|
|
/* The d3d versions do not agree on the exact messages here. D3d8 restores
|
|
|
|
* the window but leaves the size untouched, d3d9 sets the size on an
|
|
|
|
* invisible window, generates messages but doesn't change the window
|
|
|
|
* properties. The implementation follows d3d9.
|
|
|
|
*
|
|
|
|
* Guild Wars 1 wants a WINDOWPOSCHANGED message on the device window to
|
|
|
|
* resume drawing after a focus loss. */
|
2020-11-02 10:44:57 +01:00
|
|
|
output = wined3d_swapchain_get_output(swapchain);
|
|
|
|
if (!output)
|
|
|
|
{
|
|
|
|
ERR("Failed to get output from swapchain %p.\n", swapchain);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 09:45:51 +02:00
|
|
|
if (SUCCEEDED(hr = wined3d_output_get_desc(output, &output_desc)))
|
|
|
|
SetWindowPos(window, NULL, output_desc.desktop_rect.left,
|
|
|
|
output_desc.desktop_rect.top, swapchain->state.desc.backbuffer_width,
|
|
|
|
swapchain->state.desc.backbuffer_height, SWP_NOACTIVATE | SWP_NOZORDER);
|
|
|
|
else
|
|
|
|
ERR("Failed to get output description, hr %#x.\n", hr);
|
2014-11-19 20:13:50 +01:00
|
|
|
}
|
|
|
|
|
2014-12-04 21:51:49 +01:00
|
|
|
if (device->wined3d->flags & WINED3D_RESTORE_MODE_ON_ACTIVATE)
|
2014-11-18 21:26:57 +01:00
|
|
|
{
|
2020-11-02 10:44:57 +01:00
|
|
|
output = wined3d_swapchain_get_output(swapchain);
|
|
|
|
if (!output)
|
|
|
|
{
|
|
|
|
ERR("Failed to get output from swapchain %p.\n", swapchain);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 09:45:51 +02:00
|
|
|
if (FAILED(hr = wined3d_output_set_display_mode(output,
|
2020-03-06 14:16:16 +01:00
|
|
|
&swapchain->state.d3d_mode)))
|
2020-05-15 09:45:51 +02:00
|
|
|
ERR("Failed to set display mode, hr %#x.\n", hr);
|
2014-11-18 21:26:57 +01:00
|
|
|
}
|
2018-10-14 01:13:51 +02:00
|
|
|
|
|
|
|
if (swapchain == device->swapchains[0])
|
|
|
|
device->device_parent->ops->activate(device->device_parent, TRUE);
|
2014-11-18 21:26:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-05 15:55:35 +02:00
|
|
|
if (device->restore_screensaver)
|
|
|
|
{
|
|
|
|
SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0);
|
|
|
|
device->restore_screensaver = FALSE;
|
|
|
|
}
|
|
|
|
|
2020-11-02 10:44:57 +01:00
|
|
|
if (FAILED(hr = wined3d_restore_display_modes(device->wined3d)))
|
|
|
|
ERR("Failed to restore display modes, hr %#x.\n", hr);
|
2014-11-18 21:26:57 +01:00
|
|
|
|
|
|
|
swapchain->reapply_mode = TRUE;
|
|
|
|
|
2018-10-14 01:13:51 +02:00
|
|
|
/* Some DDraw apps (Deus Ex: GOTY, and presumably all UT 1 based games) destroy the device
|
|
|
|
* during window minimization. Do our housekeeping now, as the device may not exist after
|
|
|
|
* the ShowWindow call.
|
|
|
|
*
|
|
|
|
* In d3d9, the device is marked lost after the window is minimized. If we find an app
|
|
|
|
* that needs this behavior (e.g. because it calls TestCooperativeLevel in the window proc)
|
|
|
|
* we'll have to control this via a create flag. Note that the device and swapchain are not
|
|
|
|
* safe to access after the ShowWindow call. */
|
|
|
|
if (swapchain == device->swapchains[0])
|
|
|
|
device->device_parent->ops->activate(device->device_parent, FALSE);
|
|
|
|
|
2019-07-29 13:30:53 +02:00
|
|
|
if (!(device->create_parms.flags & WINED3DCREATE_NOWINDOWCHANGES) && IsWindowVisible(window))
|
|
|
|
ShowWindow(window, SW_MINIMIZE);
|
2014-11-18 21:26:57 +01:00
|
|
|
}
|
2014-12-04 21:51:49 +01:00
|
|
|
|
2018-10-14 01:13:52 +02:00
|
|
|
if (!focus_messages)
|
2019-07-29 13:30:53 +02:00
|
|
|
wined3d_filter_messages(window, filter);
|
2014-11-13 20:39:25 +01:00
|
|
|
}
|
2015-08-07 10:01:33 +02:00
|
|
|
|
2015-08-07 10:01:34 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_resize_buffers(struct wined3d_swapchain *swapchain, unsigned int buffer_count,
|
2015-08-07 10:01:33 +02:00
|
|
|
unsigned int width, unsigned int height, enum wined3d_format_id format_id,
|
|
|
|
enum wined3d_multisample_type multisample_type, unsigned int multisample_quality)
|
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
struct wined3d_swapchain_desc *desc = &swapchain->state.desc;
|
2015-08-07 10:01:33 +02:00
|
|
|
BOOL update_desc = FALSE;
|
|
|
|
|
|
|
|
TRACE("swapchain %p, buffer_count %u, width %u, height %u, format %s, "
|
|
|
|
"multisample_type %#x, multisample_quality %#x.\n",
|
|
|
|
swapchain, buffer_count, width, height, debug_d3dformat(format_id),
|
|
|
|
multisample_type, multisample_quality);
|
|
|
|
|
2016-03-15 16:55:08 +01:00
|
|
|
wined3d_swapchain_apply_sample_count_override(swapchain, format_id, &multisample_type, &multisample_quality);
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (buffer_count && buffer_count != desc->backbuffer_count)
|
2015-08-07 10:01:33 +02:00
|
|
|
FIXME("Cannot change the back buffer count yet.\n");
|
|
|
|
|
2018-11-29 14:33:47 +01:00
|
|
|
wined3d_cs_finish(swapchain->device->cs, WINED3D_CS_QUEUE_DEFAULT);
|
2017-05-02 11:35:30 +02:00
|
|
|
|
2015-08-07 10:01:33 +02:00
|
|
|
if (!width || !height)
|
|
|
|
{
|
|
|
|
/* The application is requesting that either the swapchain width or
|
|
|
|
* height be set to the corresponding dimension in the window's
|
|
|
|
* client rect. */
|
|
|
|
|
|
|
|
RECT client_rect;
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (!desc->windowed)
|
2015-08-07 10:01:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
if (!GetClientRect(swapchain->state.device_window, &client_rect))
|
2015-08-07 10:01:33 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get client rect, last error %#x.\n", GetLastError());
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!width)
|
|
|
|
width = client_rect.right;
|
|
|
|
|
|
|
|
if (!height)
|
|
|
|
height = client_rect.bottom;
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (width != desc->backbuffer_width || height != desc->backbuffer_height)
|
2015-08-07 10:01:33 +02:00
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
desc->backbuffer_width = width;
|
|
|
|
desc->backbuffer_height = height;
|
2015-08-07 10:01:33 +02:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format_id == WINED3DFMT_UNKNOWN)
|
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
if (!desc->windowed)
|
2015-08-07 10:01:33 +02:00
|
|
|
return WINED3DERR_INVALIDCALL;
|
2019-07-31 22:29:49 +02:00
|
|
|
format_id = swapchain->state.original_mode.format_id;
|
2015-08-07 10:01:33 +02:00
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (format_id != desc->backbuffer_format)
|
2015-08-07 10:01:33 +02:00
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
desc->backbuffer_format = format_id;
|
2015-08-07 10:01:33 +02:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (multisample_type != desc->multisample_type
|
|
|
|
|| multisample_quality != desc->multisample_quality)
|
2015-08-07 10:01:33 +02:00
|
|
|
{
|
2019-07-29 13:30:55 +02:00
|
|
|
desc->multisample_type = multisample_type;
|
|
|
|
desc->multisample_quality = multisample_quality;
|
2015-08-07 10:01:33 +02:00
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_desc)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
|
|
|
|
2020-06-17 00:54:26 +02:00
|
|
|
if (FAILED(hr = wined3d_texture_update_desc(swapchain->front_buffer, 0, desc->backbuffer_width,
|
2019-07-29 13:30:55 +02:00
|
|
|
desc->backbuffer_height, desc->backbuffer_format,
|
|
|
|
desc->multisample_type, desc->multisample_quality, NULL, 0)))
|
2015-08-07 10:01:33 +02:00
|
|
|
return hr;
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
for (i = 0; i < desc->backbuffer_count; ++i)
|
2015-08-07 10:01:33 +02:00
|
|
|
{
|
2020-06-17 00:54:26 +02:00
|
|
|
if (FAILED(hr = wined3d_texture_update_desc(swapchain->back_buffers[i], 0, desc->backbuffer_width,
|
2019-07-29 13:30:55 +02:00
|
|
|
desc->backbuffer_height, desc->backbuffer_format,
|
|
|
|
desc->multisample_type, desc->multisample_quality, NULL, 0)))
|
2015-08-07 10:01:33 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
swapchain_update_render_to_fbo(swapchain);
|
|
|
|
swapchain_update_draw_bindings(swapchain);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2016-08-01 22:28:35 +02:00
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
static HRESULT wined3d_swapchain_state_set_display_mode(struct wined3d_swapchain_state *state,
|
2020-03-06 14:16:48 +01:00
|
|
|
struct wined3d_output *output, struct wined3d_display_mode *mode)
|
2016-08-25 12:22:56 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
if (state->desc.flags & WINED3D_SWAPCHAIN_USE_CLOSEST_MATCHING_MODE)
|
2016-08-25 12:22:56 +02:00
|
|
|
{
|
2020-03-06 14:16:48 +01:00
|
|
|
if (FAILED(hr = wined3d_output_find_closest_matching_mode(output, mode)))
|
2016-08-25 12:22:56 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to find closest matching mode, hr %#x.\n", hr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 09:46:04 +02:00
|
|
|
if (output != state->desc.output)
|
|
|
|
{
|
2020-11-02 10:44:57 +01:00
|
|
|
if (FAILED(hr = wined3d_restore_display_modes(state->wined3d)))
|
2020-05-15 09:46:04 +02:00
|
|
|
{
|
2020-11-02 10:44:57 +01:00
|
|
|
WARN("Failed to restore display modes, hr %#x.\n", hr);
|
2020-05-15 09:46:04 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = wined3d_output_get_display_mode(output, &state->original_mode, NULL)))
|
|
|
|
{
|
|
|
|
WARN("Failed to get current display mode, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-06 14:16:16 +01:00
|
|
|
if (FAILED(hr = wined3d_output_set_display_mode(output, mode)))
|
2016-08-25 12:22:56 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to set display mode, hr %#x.\n", hr);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_state_resize_target(struct wined3d_swapchain_state *state,
|
2020-05-15 09:46:41 +02:00
|
|
|
const struct wined3d_display_mode *mode)
|
2016-08-04 17:23:42 +02:00
|
|
|
{
|
2016-08-25 12:22:56 +02:00
|
|
|
struct wined3d_display_mode actual_mode;
|
2020-05-05 14:46:30 +02:00
|
|
|
struct wined3d_output_desc output_desc;
|
2016-08-04 17:23:42 +02:00
|
|
|
RECT original_window_rect, window_rect;
|
2020-05-05 14:46:30 +02:00
|
|
|
int x, y, width, height;
|
2018-11-29 14:33:40 +01:00
|
|
|
HWND window;
|
2016-08-04 17:23:42 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-05-15 09:46:41 +02:00
|
|
|
TRACE("state %p, mode %p.\n", state, mode);
|
2016-08-04 17:23:42 +02:00
|
|
|
|
2018-11-29 14:33:40 +01:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
|
2019-07-31 22:29:46 +02:00
|
|
|
window = state->device_window;
|
2018-11-29 14:33:40 +01:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (state->desc.windowed)
|
2016-08-04 17:23:42 +02:00
|
|
|
{
|
2016-08-25 12:22:56 +02:00
|
|
|
SetRect(&window_rect, 0, 0, mode->width, mode->height);
|
2016-08-04 17:23:42 +02:00
|
|
|
AdjustWindowRectEx(&window_rect,
|
2018-11-29 14:33:40 +01:00
|
|
|
GetWindowLongW(window, GWL_STYLE), FALSE,
|
|
|
|
GetWindowLongW(window, GWL_EXSTYLE));
|
|
|
|
GetWindowRect(window, &original_window_rect);
|
2020-05-05 14:46:30 +02:00
|
|
|
|
|
|
|
x = original_window_rect.left;
|
|
|
|
y = original_window_rect.top;
|
|
|
|
width = window_rect.right - window_rect.left;
|
|
|
|
height = window_rect.bottom - window_rect.top;
|
2016-08-04 17:23:42 +02:00
|
|
|
}
|
2020-05-05 14:46:30 +02:00
|
|
|
else
|
2016-08-04 17:23:42 +02:00
|
|
|
{
|
2020-05-05 14:46:30 +02:00
|
|
|
if (state->desc.flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
|
2018-11-29 14:33:40 +01:00
|
|
|
{
|
2020-05-05 14:46:30 +02:00
|
|
|
actual_mode = *mode;
|
2020-05-15 09:46:41 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_state_set_display_mode(state, state->desc.output,
|
|
|
|
&actual_mode)))
|
2020-05-05 14:46:30 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to set display mode, hr %#x.\n", hr);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
return hr;
|
|
|
|
}
|
2018-11-29 14:33:40 +01:00
|
|
|
}
|
2020-05-05 14:46:30 +02:00
|
|
|
|
2020-05-15 09:46:41 +02:00
|
|
|
if (FAILED(hr = wined3d_output_get_desc(state->desc.output, &output_desc)))
|
2016-08-04 17:23:42 +02:00
|
|
|
{
|
2020-05-05 14:46:30 +02:00
|
|
|
ERR("Failed to get output description, hr %#x.\n", hr);
|
2018-11-29 14:33:40 +01:00
|
|
|
wined3d_mutex_unlock();
|
2018-11-23 14:41:16 +01:00
|
|
|
return hr;
|
2016-08-04 17:23:42 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 14:46:30 +02:00
|
|
|
x = output_desc.desktop_rect.left;
|
|
|
|
y = output_desc.desktop_rect.top;
|
|
|
|
width = output_desc.desktop_rect.right - output_desc.desktop_rect.left;
|
|
|
|
height = output_desc.desktop_rect.bottom - output_desc.desktop_rect.top;
|
2016-08-04 17:23:42 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 14:33:40 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2020-05-05 14:46:30 +02:00
|
|
|
MoveWindow(window, x, y, width, height, TRUE);
|
2016-08-04 17:23:42 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:54 +02:00
|
|
|
static LONG fullscreen_style(LONG style)
|
|
|
|
{
|
|
|
|
/* Make sure the window is managed, otherwise we won't get keyboard input. */
|
|
|
|
style |= WS_POPUP | WS_SYSMENU;
|
|
|
|
style &= ~(WS_CAPTION | WS_THICKFRAME);
|
|
|
|
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG fullscreen_exstyle(LONG exstyle)
|
|
|
|
{
|
|
|
|
/* Filter out window decorations. */
|
|
|
|
exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
|
|
|
|
|
|
|
|
return exstyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT wined3d_swapchain_state_setup_fullscreen(struct wined3d_swapchain_state *state,
|
2020-05-07 09:52:12 +02:00
|
|
|
HWND window, int x, int y, int width, int height)
|
2019-07-29 13:30:54 +02:00
|
|
|
{
|
2020-07-07 21:13:13 +02:00
|
|
|
unsigned int window_pos_flags = SWP_FRAMECHANGED | SWP_NOACTIVATE;
|
2019-07-29 13:30:54 +02:00
|
|
|
LONG style, exstyle;
|
|
|
|
BOOL filter;
|
|
|
|
|
|
|
|
TRACE("Setting up window %p for fullscreen mode.\n", window);
|
|
|
|
|
|
|
|
if (!IsWindow(window))
|
|
|
|
{
|
|
|
|
WARN("%p is not a valid window.\n", window);
|
|
|
|
return WINED3DERR_NOTAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->style || state->exstyle)
|
|
|
|
{
|
|
|
|
ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
|
|
|
|
window, state->style, state->exstyle);
|
|
|
|
}
|
|
|
|
|
2020-07-07 21:13:12 +02:00
|
|
|
if (state->desc.flags & WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES)
|
|
|
|
window_pos_flags |= SWP_NOZORDER;
|
2020-07-07 21:13:13 +02:00
|
|
|
else
|
|
|
|
window_pos_flags |= SWP_SHOWWINDOW;
|
2020-07-07 21:13:12 +02:00
|
|
|
|
2019-07-29 13:30:54 +02:00
|
|
|
state->style = GetWindowLongW(window, GWL_STYLE);
|
|
|
|
state->exstyle = GetWindowLongW(window, GWL_EXSTYLE);
|
|
|
|
|
|
|
|
style = fullscreen_style(state->style);
|
|
|
|
exstyle = fullscreen_exstyle(state->exstyle);
|
|
|
|
|
|
|
|
TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
|
|
|
|
state->style, state->exstyle, style, exstyle);
|
|
|
|
|
|
|
|
filter = wined3d_filter_messages(window, TRUE);
|
|
|
|
|
|
|
|
SetWindowLongW(window, GWL_STYLE, style);
|
|
|
|
SetWindowLongW(window, GWL_EXSTYLE, exstyle);
|
2020-07-07 21:13:12 +02:00
|
|
|
SetWindowPos(window, HWND_TOPMOST, x, y, width, height, window_pos_flags);
|
2019-07-29 13:30:54 +02:00
|
|
|
|
|
|
|
wined3d_filter_messages(window, filter);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:29:45 +02:00
|
|
|
void wined3d_swapchain_state_restore_from_fullscreen(struct wined3d_swapchain_state *state,
|
2019-07-29 13:30:54 +02:00
|
|
|
HWND window, const RECT *window_rect)
|
|
|
|
{
|
|
|
|
unsigned int window_pos_flags = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE;
|
2020-07-07 21:13:15 +02:00
|
|
|
HWND window_pos_after = NULL;
|
2019-07-29 13:30:54 +02:00
|
|
|
LONG style, exstyle;
|
|
|
|
RECT rect = {0};
|
|
|
|
BOOL filter;
|
|
|
|
|
|
|
|
if (!state->style && !state->exstyle)
|
|
|
|
return;
|
|
|
|
|
2020-07-07 21:13:15 +02:00
|
|
|
if ((state->desc.flags & WINED3D_SWAPCHAIN_RESTORE_WINDOW_STATE)
|
|
|
|
&& !(state->desc.flags & WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES))
|
|
|
|
{
|
|
|
|
window_pos_after = (state->exstyle & WS_EX_TOPMOST) ? HWND_TOPMOST : HWND_NOTOPMOST;
|
|
|
|
window_pos_flags |= (state->style & WS_VISIBLE) ? SWP_SHOWWINDOW : SWP_HIDEWINDOW;
|
|
|
|
window_pos_flags &= ~SWP_NOZORDER;
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:54 +02:00
|
|
|
style = GetWindowLongW(window, GWL_STYLE);
|
|
|
|
exstyle = GetWindowLongW(window, GWL_EXSTYLE);
|
|
|
|
|
|
|
|
/* These flags are set by wined3d_device_setup_fullscreen_window, not the
|
|
|
|
* application, and we want to ignore them in the test below, since it's
|
|
|
|
* not the application's fault that they changed. Additionally, we want to
|
|
|
|
* preserve the current status of these flags (i.e. don't restore them) to
|
|
|
|
* more closely emulate the behavior of Direct3D, which leaves these flags
|
|
|
|
* alone when returning to windowed mode. */
|
|
|
|
state->style ^= (state->style ^ style) & WS_VISIBLE;
|
|
|
|
state->exstyle ^= (state->exstyle ^ exstyle) & WS_EX_TOPMOST;
|
|
|
|
|
|
|
|
TRACE("Restoring window style of window %p to %08x, %08x.\n",
|
|
|
|
window, state->style, state->exstyle);
|
|
|
|
|
|
|
|
filter = wined3d_filter_messages(window, TRUE);
|
|
|
|
|
|
|
|
/* Only restore the style if the application didn't modify it during the
|
|
|
|
* fullscreen phase. Some applications change it before calling Reset()
|
|
|
|
* when switching between windowed and fullscreen modes (HL2), some
|
|
|
|
* depend on the original style (Eve Online). */
|
|
|
|
if (style == fullscreen_style(state->style) && exstyle == fullscreen_exstyle(state->exstyle))
|
|
|
|
{
|
|
|
|
SetWindowLongW(window, GWL_STYLE, state->style);
|
|
|
|
SetWindowLongW(window, GWL_EXSTYLE, state->exstyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_rect)
|
|
|
|
rect = *window_rect;
|
|
|
|
else
|
|
|
|
window_pos_flags |= (SWP_NOMOVE | SWP_NOSIZE);
|
2020-07-07 21:13:15 +02:00
|
|
|
SetWindowPos(window, window_pos_after, rect.left, rect.top,
|
2019-07-29 13:30:54 +02:00
|
|
|
rect.right - rect.left, rect.bottom - rect.top, window_pos_flags);
|
|
|
|
|
|
|
|
wined3d_filter_messages(window, filter);
|
|
|
|
|
|
|
|
/* Delete the old values. */
|
|
|
|
state->style = 0;
|
|
|
|
state->exstyle = 0;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:29:49 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_state *state,
|
2020-05-15 09:46:14 +02:00
|
|
|
const struct wined3d_swapchain_desc *swapchain_desc,
|
2020-03-06 14:16:48 +01:00
|
|
|
const struct wined3d_display_mode *mode)
|
2016-08-01 22:28:35 +02:00
|
|
|
{
|
2016-08-25 12:22:54 +02:00
|
|
|
struct wined3d_display_mode actual_mode;
|
2020-05-07 09:52:12 +02:00
|
|
|
struct wined3d_output_desc output_desc;
|
2020-10-09 11:56:53 +02:00
|
|
|
BOOL windowed = state->desc.windowed;
|
2016-08-01 22:28:35 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-05-15 09:46:14 +02:00
|
|
|
TRACE("state %p, swapchain_desc %p, mode %p.\n", state, swapchain_desc, mode);
|
2016-08-01 22:28:35 +02:00
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (state->desc.flags & WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH)
|
2016-08-01 22:28:35 +02:00
|
|
|
{
|
2016-08-25 12:22:54 +02:00
|
|
|
if (mode)
|
|
|
|
{
|
|
|
|
actual_mode = *mode;
|
2020-11-02 10:44:57 +01:00
|
|
|
if (FAILED(hr = wined3d_swapchain_state_set_display_mode(state, swapchain_desc->output,
|
|
|
|
&actual_mode)))
|
|
|
|
return hr;
|
2016-08-25 12:22:54 +02:00
|
|
|
}
|
|
|
|
else
|
2016-08-03 09:41:38 +02:00
|
|
|
{
|
|
|
|
if (!swapchain_desc->windowed)
|
|
|
|
{
|
2016-08-25 12:22:54 +02:00
|
|
|
actual_mode.width = swapchain_desc->backbuffer_width;
|
|
|
|
actual_mode.height = swapchain_desc->backbuffer_height;
|
|
|
|
actual_mode.refresh_rate = swapchain_desc->refresh_rate;
|
2020-05-15 09:46:14 +02:00
|
|
|
actual_mode.format_id = adapter_format_from_backbuffer_format(swapchain_desc->output->adapter,
|
2019-03-14 16:30:12 +01:00
|
|
|
swapchain_desc->backbuffer_format);
|
2016-08-25 12:22:54 +02:00
|
|
|
actual_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
|
2020-11-02 10:44:57 +01:00
|
|
|
if (FAILED(hr = wined3d_swapchain_state_set_display_mode(state, swapchain_desc->output,
|
|
|
|
&actual_mode)))
|
|
|
|
return hr;
|
2016-08-03 09:41:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-02 10:44:57 +01:00
|
|
|
if (FAILED(hr = wined3d_restore_display_modes(state->wined3d)))
|
|
|
|
{
|
|
|
|
WARN("Failed to restore display modes for all outputs, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
2016-08-03 09:41:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (mode)
|
|
|
|
WARN("WINED3D_SWAPCHAIN_ALLOW_MODE_SWITCH is not set, ignoring mode.\n");
|
|
|
|
|
2020-05-15 09:46:14 +02:00
|
|
|
if (FAILED(hr = wined3d_output_get_display_mode(swapchain_desc->output, &actual_mode,
|
|
|
|
NULL)))
|
2016-08-01 22:28:35 +02:00
|
|
|
{
|
2016-08-03 09:41:38 +02:00
|
|
|
ERR("Failed to get display mode, hr %#x.\n", hr);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
2016-08-01 22:28:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!swapchain_desc->windowed)
|
|
|
|
{
|
2016-08-25 12:22:54 +02:00
|
|
|
unsigned int width = actual_mode.width;
|
|
|
|
unsigned int height = actual_mode.height;
|
|
|
|
|
2020-05-15 09:46:14 +02:00
|
|
|
if (FAILED(hr = wined3d_output_get_desc(swapchain_desc->output, &output_desc)))
|
2020-05-07 09:52:12 +02:00
|
|
|
{
|
|
|
|
ERR("Failed to get output description, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-07-29 13:30:55 +02:00
|
|
|
if (state->desc.windowed)
|
2016-08-01 22:28:35 +02:00
|
|
|
{
|
2016-12-13 13:10:38 +01:00
|
|
|
/* Switch from windowed to fullscreen */
|
2020-05-07 09:52:12 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_state_setup_fullscreen(state, state->device_window,
|
|
|
|
output_desc.desktop_rect.left, output_desc.desktop_rect.top, width, height)))
|
2019-06-19 23:59:48 +02:00
|
|
|
return hr;
|
2016-08-01 22:28:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-31 22:29:49 +02:00
|
|
|
HWND window = state->device_window;
|
2019-07-29 13:30:53 +02:00
|
|
|
BOOL filter;
|
2016-12-13 13:10:38 +01:00
|
|
|
|
2019-07-29 13:30:53 +02:00
|
|
|
/* Fullscreen -> fullscreen mode change */
|
|
|
|
filter = wined3d_filter_messages(window, TRUE);
|
2020-05-07 09:52:12 +02:00
|
|
|
MoveWindow(window, output_desc.desktop_rect.left, output_desc.desktop_rect.top, width,
|
|
|
|
height, TRUE);
|
2019-07-29 13:30:53 +02:00
|
|
|
ShowWindow(window, SW_SHOW);
|
|
|
|
wined3d_filter_messages(window, filter);
|
2016-08-01 22:28:35 +02:00
|
|
|
}
|
2019-07-31 22:29:49 +02:00
|
|
|
state->d3d_mode = actual_mode;
|
2016-08-01 22:28:35 +02:00
|
|
|
}
|
2019-07-29 13:30:55 +02:00
|
|
|
else if (!state->desc.windowed)
|
2016-08-01 22:28:35 +02:00
|
|
|
{
|
|
|
|
/* Fullscreen -> windowed switch */
|
2016-12-13 13:10:38 +01:00
|
|
|
RECT *window_rect = NULL;
|
2019-07-29 13:30:55 +02:00
|
|
|
if (state->desc.flags & WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT)
|
2019-07-31 22:29:49 +02:00
|
|
|
window_rect = &state->original_window_rect;
|
2019-07-31 22:29:46 +02:00
|
|
|
wined3d_swapchain_state_restore_from_fullscreen(state, state->device_window, window_rect);
|
2016-08-01 22:28:35 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 09:46:14 +02:00
|
|
|
state->desc.output = swapchain_desc->output;
|
2019-07-29 13:30:55 +02:00
|
|
|
state->desc.windowed = swapchain_desc->windowed;
|
2016-08-01 22:28:35 +02:00
|
|
|
|
2020-10-09 11:56:53 +02:00
|
|
|
if (windowed != state->desc.windowed)
|
|
|
|
state->parent->ops->windowed_state_changed(state->parent, state->desc.windowed);
|
|
|
|
|
2016-08-01 22:28:35 +02:00
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2019-07-31 22:29:47 +02:00
|
|
|
|
2020-10-05 11:24:16 +02:00
|
|
|
BOOL CDECL wined3d_swapchain_state_is_windowed(const struct wined3d_swapchain_state *state)
|
|
|
|
{
|
|
|
|
TRACE("state %p.\n", state);
|
|
|
|
|
|
|
|
return state->desc.windowed;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:29:47 +02:00
|
|
|
void CDECL wined3d_swapchain_state_destroy(struct wined3d_swapchain_state *state)
|
|
|
|
{
|
2020-10-12 10:41:01 +02:00
|
|
|
wined3d_swapchain_state_cleanup(state);
|
2019-07-31 22:29:47 +02:00
|
|
|
heap_free(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CDECL wined3d_swapchain_state_create(const struct wined3d_swapchain_desc *desc,
|
2020-10-09 11:56:53 +02:00
|
|
|
HWND window, struct wined3d *wined3d, struct wined3d_swapchain_state_parent *state_parent,
|
|
|
|
struct wined3d_swapchain_state **state)
|
2019-07-31 22:29:47 +02:00
|
|
|
{
|
|
|
|
struct wined3d_swapchain_state *s;
|
2019-07-31 22:29:49 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2020-10-09 11:56:42 +02:00
|
|
|
TRACE("desc %p, window %p, wined3d %p, state %p.\n", desc, window, wined3d, state);
|
2019-07-31 22:29:47 +02:00
|
|
|
|
|
|
|
if (!(s = heap_alloc_zero(sizeof(*s))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2020-10-09 11:56:53 +02:00
|
|
|
if (FAILED(hr = wined3d_swapchain_state_init(s, desc, window, wined3d, state_parent)))
|
2019-08-05 15:30:00 +02:00
|
|
|
{
|
|
|
|
heap_free(s);
|
2019-07-31 22:29:49 +02:00
|
|
|
return hr;
|
2019-08-05 15:30:00 +02:00
|
|
|
}
|
2019-07-31 22:29:47 +02:00
|
|
|
|
|
|
|
*state = s;
|
|
|
|
|
2019-07-31 22:29:49 +02:00
|
|
|
return hr;
|
2019-07-31 22:29:47 +02:00
|
|
|
}
|