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);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(fps);
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2011-04-13 19:14:32 +02:00
|
|
|
static void swapchain_cleanup(struct wined3d_swapchain *swapchain)
|
2011-04-07 18:46:00 +02:00
|
|
|
{
|
2012-06-22 15:57:27 +02: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
|
|
|
|
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)
|
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
i = swapchain->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]);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->back_buffers);
|
|
|
|
swapchain->back_buffers = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < swapchain->num_contexts; ++i)
|
|
|
|
{
|
|
|
|
context_destroy(swapchain->device, swapchain->context[i]);
|
|
|
|
}
|
2011-04-12 18:28:40 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
2011-04-07 18:46:00 +02:00
|
|
|
|
|
|
|
/* 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. */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain->desc.windowed && swapchain->desc.auto_restore_display_mode)
|
2011-04-07 18:46:00 +02:00
|
|
|
{
|
2012-06-22 15:57:27 +02:00
|
|
|
if (FAILED(hr = wined3d_set_adapter_display_mode(swapchain->device->wined3d,
|
2013-08-20 10:20:09 +02:00
|
|
|
swapchain->device->adapter->ordinal, &swapchain->original_mode)))
|
2012-06-22 15:57:27 +02:00
|
|
|
ERR("Failed to restore display mode, hr %#x.\n", hr);
|
2011-04-07 18:46:00 +02:00
|
|
|
}
|
2011-04-12 22:27:54 +02:00
|
|
|
|
|
|
|
if (swapchain->backup_dc)
|
|
|
|
{
|
|
|
|
TRACE("Destroying backup wined3d window %p, dc %p.\n", swapchain->backup_wnd, swapchain->backup_dc);
|
|
|
|
|
2013-11-04 10:02:43 +01:00
|
|
|
wined3d_release_dc(swapchain->backup_wnd, swapchain->backup_dc);
|
2011-04-12 22:27:54 +02:00
|
|
|
DestroyWindow(swapchain->backup_wnd);
|
|
|
|
}
|
2011-04-07 18:46:00 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
swapchain_cleanup(swapchain);
|
|
|
|
swapchain->parent_ops->wined3d_object_destroyed(swapchain->parent);
|
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain);
|
|
|
|
}
|
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)
|
|
|
|
window = swapchain->device_window;
|
|
|
|
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);
|
|
|
|
swapchain->win_handle = window;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
HRESULT CDECL wined3d_swapchain_present(struct wined3d_swapchain *swapchain,
|
2011-04-13 19:14:30 +02:00
|
|
|
const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
|
|
|
|
const RGNDATA *dirty_region, DWORD flags)
|
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
TRACE("swapchain %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
|
|
|
|
swapchain, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
|
2011-04-13 19:14:30 +02:00
|
|
|
dst_window_override, dirty_region, flags);
|
|
|
|
|
2012-06-29 07:37:56 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME("Ignoring flags %#x.\n", flags);
|
|
|
|
|
2012-04-15 18:57:13 +02:00
|
|
|
if (!swapchain->back_buffers)
|
|
|
|
{
|
|
|
|
WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2013-09-27 00:15:13 +02:00
|
|
|
wined3d_cs_emit_present(swapchain->device->cs, swapchain, src_rect,
|
|
|
|
dst_rect, dst_window_override, dirty_region, flags);
|
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
|
|
|
{
|
2015-10-16 13:59:17 +02:00
|
|
|
struct wined3d_surface *src_surface, *dst_surface;
|
|
|
|
struct wined3d_resource *sub_resource;
|
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
|
|
|
|
2015-10-16 13:59:17 +02:00
|
|
|
if (!(sub_resource = wined3d_texture_get_sub_resource(dst_texture, sub_resource_idx)) ||
|
|
|
|
sub_resource->type != WINED3D_RTYPE_SURFACE)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
dst_surface = surface_from_resource(sub_resource);
|
2014-08-20 13:20:02 +02:00
|
|
|
src_surface = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0));
|
2011-11-02 22:46:53 +01:00
|
|
|
SetRect(&src_rect, 0, 0, src_surface->resource.width, src_surface->resource.height);
|
|
|
|
dst_rect = src_rect;
|
2011-04-07 18:45:59 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain->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
|
|
|
|
2012-01-12 21:43:12 +01:00
|
|
|
return wined3d_surface_blt(dst_surface, &dst_rect, src_surface, &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. */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain->back_buffers || back_buffer_idx >= swapchain->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
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2012-07-18 21:32:30 +02:00
|
|
|
return wined3d_get_adapter_raster_status(swapchain->device->wined3d,
|
|
|
|
swapchain->device->adapter->ordinal, raster_status);
|
2011-04-07 18:45:59 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-06-27 19:02:28 +02:00
|
|
|
hr = wined3d_get_adapter_display_mode(swapchain->device->wined3d,
|
2012-06-27 19:02:29 +02:00
|
|
|
swapchain->device->adapter->ordinal, 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
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
*desc = swapchain->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);
|
|
|
|
|
|
|
|
dc = GetDC(swapchain->device_window);
|
|
|
|
SetDeviceGammaRamp(dc, (void *)ramp);
|
|
|
|
ReleaseDC(swapchain->device_window, dc);
|
|
|
|
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
|
|
|
dc = GetDC(swapchain->device_window);
|
|
|
|
GetDeviceGammaRamp(dc, ramp);
|
|
|
|
ReleaseDC(swapchain->device_window, dc);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-08-20 13:20:03 +02:00
|
|
|
struct wined3d_surface *backbuffer = surface_from_resource(
|
|
|
|
wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0));
|
2010-01-03 21:18:25 +01:00
|
|
|
UINT src_w = src_rect->right - src_rect->left;
|
|
|
|
UINT src_h = src_rect->bottom - src_rect->top;
|
2009-12-06 17:39:47 +01:00
|
|
|
GLenum gl_filter;
|
|
|
|
const struct wined3d_gl_info *gl_info = context->gl_info;
|
2010-05-18 09:53:09 +02:00
|
|
|
RECT win_rect;
|
|
|
|
UINT win_h;
|
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
|
|
|
|
|
|
|
if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top)
|
|
|
|
gl_filter = GL_NEAREST;
|
|
|
|
else
|
|
|
|
gl_filter = GL_LINEAR;
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2011-04-13 19:14:32 +02:00
|
|
|
GetClientRect(swapchain->win_handle, &win_rect);
|
2010-05-18 09:53:09 +02:00
|
|
|
win_h = win_rect.bottom - win_rect.top;
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format->color_fixup))
|
2009-12-06 17:39:47 +01:00
|
|
|
{
|
2014-01-17 13:27:16 +01:00
|
|
|
DWORD location = WINED3D_LOCATION_TEXTURE_RGB;
|
2011-08-25 21:05:03 +02:00
|
|
|
|
|
|
|
if (backbuffer->resource.multisample_type)
|
|
|
|
{
|
2014-01-17 13:27:16 +01:00
|
|
|
location = WINED3D_LOCATION_RB_RESOLVED;
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(backbuffer, context, location);
|
2011-08-25 21:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, backbuffer, NULL, location);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glReadBuffer(GL_COLOR_ATTACHMENT0);
|
2011-04-08 20:22:52 +02:00
|
|
|
context_check_fbo_status(context, GL_READ_FRAMEBUFFER);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
context_apply_fbo_state_blit(context, GL_DRAW_FRAMEBUFFER,
|
|
|
|
surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)),
|
2014-01-17 13:27:16 +01:00
|
|
|
NULL, WINED3D_LOCATION_DRAWABLE);
|
2009-12-13 22:04:01 +01:00
|
|
|
context_set_draw_buffer(context, GL_BACK);
|
2011-07-26 19:52:45 +02:00
|
|
|
context_invalidate_state(context, STATE_FRAMEBUFFER);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE1));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE2));
|
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_COLORWRITEENABLE3));
|
2010-07-21 18:48:24 +02:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glDisable(GL_SCISSOR_TEST);
|
2011-12-19 21:00:09 +01:00
|
|
|
context_invalidate_state(context, STATE_RENDER(WINED3D_RS_SCISSORTESTENABLE));
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* Note that the texture is upside down */
|
2010-01-03 21:18:25 +01:00
|
|
|
gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
|
2010-05-18 09:53:09 +02:00
|
|
|
dst_rect->left, win_h - dst_rect->top, dst_rect->right, win_h - dst_rect->bottom,
|
|
|
|
GL_COLOR_BUFFER_BIT, gl_filter);
|
2009-12-06 17:39:47 +01:00
|
|
|
checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-07-26 19:52:45 +02:00
|
|
|
struct wined3d_device *device = swapchain->device;
|
2009-12-06 17:39:47 +01:00
|
|
|
struct wined3d_context *context2;
|
2010-01-03 21:18:25 +01:00
|
|
|
float tex_left = src_rect->left;
|
|
|
|
float tex_top = src_rect->top;
|
|
|
|
float tex_right = src_rect->right;
|
|
|
|
float tex_bottom = src_rect->bottom;
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2014-08-20 13:20:03 +02:00
|
|
|
context2 = context_acquire(device, backbuffer);
|
2010-05-03 22:03:28 +02:00
|
|
|
context_apply_blit_state(context2, device);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2014-10-09 11:50:47 +02:00
|
|
|
if (backbuffer->container->flags & WINED3D_TEXTURE_NORMALIZED_COORDS)
|
2009-12-06 17:39:47 +01:00
|
|
|
{
|
2015-07-08 15:47:00 +02:00
|
|
|
tex_left /= backbuffer->pow2Width;
|
|
|
|
tex_right /= backbuffer->pow2Width;
|
|
|
|
tex_top /= backbuffer->pow2Height;
|
|
|
|
tex_bottom /= backbuffer->pow2Height;
|
2009-12-06 17:39:47 +01:00
|
|
|
}
|
|
|
|
|
2010-08-30 20:29:49 +02:00
|
|
|
if (is_complex_fixup(backbuffer->resource.format->color_fixup))
|
2010-03-16 19:02:14 +01:00
|
|
|
gl_filter = GL_NEAREST;
|
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
context_apply_fbo_state_blit(context2, GL_FRAMEBUFFER,
|
|
|
|
surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)),
|
2014-01-17 13:27:16 +01:00
|
|
|
NULL, WINED3D_LOCATION_DRAWABLE);
|
2013-11-20 10:04:32 +01:00
|
|
|
context_bind_texture(context2, backbuffer->texture_target, backbuffer->container->texture_rgb.name);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2011-07-03 22:27:21 +02:00
|
|
|
/* Set up the texture. The surface is not in a wined3d_texture
|
|
|
|
* container, so there are no D3D texture settings to dirtify. */
|
2015-04-10 12:05:53 +02:00
|
|
|
device->blitter->set_shader(device->blit_priv, context2, backbuffer, NULL);
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter);
|
|
|
|
gl_info->gl_ops.gl.p_glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2009-12-13 22:04:01 +01:00
|
|
|
context_set_draw_buffer(context, GL_BACK);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* Set the viewport to the destination rectandle, disable any projection
|
2010-05-03 22:03:28 +02:00
|
|
|
* transformation set up by context_apply_blit_state(), and draw a
|
|
|
|
* (-1,-1)-(1,1) quad.
|
2009-12-06 17:39:47 +01:00
|
|
|
*
|
|
|
|
* Back up viewport and matrix to avoid breaking last_was_blit
|
|
|
|
*
|
2010-05-03 22:03:28 +02:00
|
|
|
* Note that context_apply_blit_state() set up viewport and ortho to
|
|
|
|
* match the surface size - we want the GL drawable(=window) size. */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPushAttrib(GL_VIEWPORT_BIT);
|
|
|
|
gl_info->gl_ops.gl.p_glViewport(dst_rect->left, win_h - dst_rect->bottom,
|
|
|
|
dst_rect->right, win_h - dst_rect->top);
|
|
|
|
gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
|
|
|
|
gl_info->gl_ops.gl.p_glPushMatrix();
|
|
|
|
gl_info->gl_ops.gl.p_glLoadIdentity();
|
|
|
|
|
|
|
|
gl_info->gl_ops.gl.p_glBegin(GL_QUADS);
|
2009-12-06 17:39:47 +01:00
|
|
|
/* bottom left */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(tex_left, tex_bottom);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(-1, -1);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* top left */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(tex_left, tex_top);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(-1, 1);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* top right */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(tex_right, tex_top);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(1, 1);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* bottom right */
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glTexCoord2f(tex_right, tex_bottom);
|
|
|
|
gl_info->gl_ops.gl.p_glVertex2i(1, -1);
|
|
|
|
gl_info->gl_ops.gl.p_glEnd();
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2012-07-24 11:32:27 +02:00
|
|
|
gl_info->gl_ops.gl.p_glPopMatrix();
|
|
|
|
gl_info->gl_ops.gl.p_glPopAttrib();
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2010-12-09 23:41:19 +01:00
|
|
|
device->blitter->unset_shader(context->gl_info);
|
2009-12-06 17:39:47 +01:00
|
|
|
checkGLcall("Swapchain present blit(manual)\n");
|
|
|
|
|
|
|
|
context_release(context2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-15 18:57:13 +02:00
|
|
|
static void swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in,
|
2011-04-13 19:14:30 +02:00
|
|
|
const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
|
2010-11-18 20:50:40 +01:00
|
|
|
{
|
2014-08-20 13:20:03 +02:00
|
|
|
struct wined3d_surface *back_buffer = surface_from_resource(
|
|
|
|
wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0));
|
2011-05-18 22:30:15 +02:00
|
|
|
const struct wined3d_fb_state *fb = &swapchain->device->fb;
|
2010-05-24 09:56:35 +02:00
|
|
|
const struct wined3d_gl_info *gl_info;
|
2009-10-28 11:00:11 +01:00
|
|
|
struct wined3d_context *context;
|
2014-08-20 13:20:02 +02:00
|
|
|
struct wined3d_surface *front;
|
2010-01-03 21:18:25 +01:00
|
|
|
RECT src_rect, dst_rect;
|
2010-01-03 21:18:26 +01:00
|
|
|
BOOL render_to_fbo;
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2012-03-26 20:28:10 +02:00
|
|
|
context = context_acquire(swapchain->device, back_buffer);
|
2010-03-17 21:59:54 +01:00
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2010-05-24 09:56:35 +02:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2013-11-18 10:46:16 +01:00
|
|
|
if (swapchain->device->logo_texture)
|
|
|
|
{
|
|
|
|
struct wined3d_surface *src_surface = surface_from_resource(
|
|
|
|
wined3d_texture_get_sub_resource(swapchain->device->logo_texture, 0));
|
|
|
|
RECT rect = {0, 0, src_surface->resource.width, src_surface->resource.height};
|
|
|
|
|
|
|
|
/* Blit the logo into the upper left corner of the drawable. */
|
2014-01-10 10:43:04 +01:00
|
|
|
wined3d_surface_blt(back_buffer, &rect, src_surface, &rect, WINEDDBLT_ALPHATEST,
|
2013-11-18 10:46:16 +01:00
|
|
|
NULL, WINED3D_TEXF_POINT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->device->bCursorVisible && swapchain->device->cursor_texture
|
|
|
|
&& !swapchain->device->hardwareCursor)
|
2009-12-09 20:32:08 +01:00
|
|
|
{
|
2013-11-18 10:46:16 +01:00
|
|
|
struct wined3d_surface *cursor = surface_from_resource(
|
|
|
|
wined3d_texture_get_sub_resource(swapchain->device->cursor_texture, 0));
|
2009-12-09 20:32:08 +01:00
|
|
|
RECT destRect =
|
|
|
|
{
|
2011-04-13 19:14:30 +02:00
|
|
|
swapchain->device->xScreenSpace - swapchain->device->xHotSpot,
|
|
|
|
swapchain->device->yScreenSpace - swapchain->device->yHotSpot,
|
|
|
|
swapchain->device->xScreenSpace + swapchain->device->cursorWidth - swapchain->device->xHotSpot,
|
|
|
|
swapchain->device->yScreenSpace + swapchain->device->cursorHeight - swapchain->device->yHotSpot,
|
2009-12-09 20:32:08 +01:00
|
|
|
};
|
2015-12-10 21:02:35 +01:00
|
|
|
RECT src_rect =
|
|
|
|
{
|
|
|
|
0, 0,
|
|
|
|
swapchain->device->cursor_texture->resource.width,
|
|
|
|
swapchain->device->cursor_texture->resource.height
|
|
|
|
};
|
|
|
|
const RECT clip_rect = {0, 0, back_buffer->resource.width, back_buffer->resource.height};
|
2009-12-09 20:32:08 +01:00
|
|
|
|
2013-11-18 10:46:16 +01:00
|
|
|
TRACE("Rendering the software cursor.\n");
|
2011-11-02 22:46:54 +01:00
|
|
|
|
2013-11-18 10:46:16 +01:00
|
|
|
if (swapchain->desc.windowed)
|
|
|
|
MapWindowPoints(NULL, swapchain->win_handle, (POINT *)&destRect, 2);
|
2015-12-10 21:02:35 +01:00
|
|
|
if (wined3d_clip_blit(&clip_rect, &destRect, &src_rect))
|
|
|
|
wined3d_surface_blt(back_buffer, &destRect, cursor, &src_rect, WINEDDBLT_ALPHATEST,
|
|
|
|
NULL, WINED3D_TEXF_POINT);
|
2007-09-01 21:22:32 +02:00
|
|
|
}
|
2006-07-23 00:03:33 +02:00
|
|
|
|
2010-02-04 18:30:08 +01:00
|
|
|
TRACE("Presenting HDC %p.\n", context->hdc);
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
render_to_fbo = swapchain->render_to_fbo;
|
2010-01-03 21:18:26 +01:00
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
if (src_rect_in)
|
2010-01-03 21:18:26 +01:00
|
|
|
{
|
2011-04-13 19:14:30 +02:00
|
|
|
src_rect = *src_rect_in;
|
2010-01-03 21:18:26 +01:00
|
|
|
if (!render_to_fbo && (src_rect.left || src_rect.top
|
2011-12-02 08:15:52 +01:00
|
|
|
|| src_rect.right != swapchain->desc.backbuffer_width
|
|
|
|
|| src_rect.bottom != swapchain->desc.backbuffer_height))
|
2010-01-03 21:18:26 +01:00
|
|
|
{
|
|
|
|
render_to_fbo = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src_rect.left = 0;
|
|
|
|
src_rect.top = 0;
|
2011-12-02 08:15:52 +01:00
|
|
|
src_rect.right = swapchain->desc.backbuffer_width;
|
|
|
|
src_rect.bottom = swapchain->desc.backbuffer_height;
|
2010-01-03 21:18:26 +01:00
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
if (dst_rect_in)
|
|
|
|
dst_rect = *dst_rect_in;
|
|
|
|
else
|
|
|
|
GetClientRect(swapchain->win_handle, &dst_rect);
|
2010-01-03 21:18:26 +01:00
|
|
|
|
|
|
|
if (!render_to_fbo && (dst_rect.left || dst_rect.top
|
2011-12-02 08:15:52 +01:00
|
|
|
|| dst_rect.right != swapchain->desc.backbuffer_width
|
|
|
|
|| dst_rect.bottom != swapchain->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
|
|
|
{
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(back_buffer, context, WINED3D_LOCATION_TEXTURE_RGB);
|
2014-01-17 13:27:16 +01:00
|
|
|
surface_invalidate_location(back_buffer, 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
|
|
|
|
{
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(back_buffer, context, back_buffer->container->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)
|
2009-12-06 17:39:47 +01:00
|
|
|
{
|
2013-12-06 11:09:56 +01:00
|
|
|
static unsigned int once;
|
|
|
|
|
|
|
|
if (swapchain->desc.swap_effect == WINED3D_SWAP_EFFECT_FLIP && !once++)
|
|
|
|
FIXME("WINED3D_SWAP_EFFECT_FLIP not implemented.\n");
|
2010-01-03 21:18:25 +01:00
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
swapchain_blit(swapchain, context, &src_rect, &dst_rect);
|
2009-12-06 17:39:47 +01:00
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
if (swapchain->num_contexts > 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 */
|
|
|
|
gl_info->gl_ops.wgl.p_wglSwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */
|
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
|
|
|
/* FPS support */
|
2006-07-05 18:35:21 +02:00
|
|
|
if (TRACE_ON(fps))
|
2005-06-23 13:05:24 +02:00
|
|
|
{
|
|
|
|
DWORD time = GetTickCount();
|
2011-04-13 19:14:30 +02:00
|
|
|
++swapchain->frames;
|
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
/* every 1.5 seconds */
|
2011-04-13 19:14:30 +02:00
|
|
|
if (time - swapchain->prev_time > 1500)
|
|
|
|
{
|
|
|
|
TRACE_(fps)("%p @ approx %.2ffps\n",
|
|
|
|
swapchain, 1000.0 * swapchain->frames / (time - swapchain->prev_time));
|
|
|
|
swapchain->prev_time = time;
|
|
|
|
swapchain->frames = 0;
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
front = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0));
|
2008-07-24 20:38:10 +02:00
|
|
|
|
2015-09-07 23:50:35 +02:00
|
|
|
surface_validate_location(front, WINED3D_LOCATION_DRAWABLE);
|
|
|
|
surface_invalidate_location(front, ~WINED3D_LOCATION_DRAWABLE);
|
|
|
|
/* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
|
|
|
|
* and INTEXTURE copies can keep their old content if they have any defined content.
|
|
|
|
* If the swapeffect is COPY, the content remains the same.
|
|
|
|
*
|
|
|
|
* The FLIP swap effect is not implemented yet. We could mark WINED3D_LOCATION_DRAWABLE
|
|
|
|
* up to date and hope WGL flipped front and back buffers and read this data into
|
|
|
|
* the FBO. Don't bother about this for now. */
|
2006-06-04 16:42:57 +02:00
|
|
|
|
2011-05-18 22:30:15 +02:00
|
|
|
if (fb->depth_stencil)
|
2009-12-09 20:32:08 +01:00
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
struct wined3d_surface *ds = wined3d_rendertarget_view_get_surface(fb->depth_stencil);
|
|
|
|
|
|
|
|
if (ds && (swapchain->desc.flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|
|
|
|
|| ds->flags & SFLAG_DISCARD))
|
2009-12-09 20:32:08 +01:00
|
|
|
{
|
2014-08-22 12:32:01 +02:00
|
|
|
surface_modify_ds_location(ds, WINED3D_LOCATION_DISCARDED,
|
|
|
|
fb->depth_stencil->width, fb->depth_stencil->height);
|
|
|
|
if (ds == swapchain->device->onscreen_depth_stencil)
|
2010-04-20 22:38:41 +02:00
|
|
|
{
|
2015-11-05 16:00:40 +01:00
|
|
|
wined3d_texture_decref(swapchain->device->onscreen_depth_stencil->container);
|
2011-04-13 19:14:30 +02:00
|
|
|
swapchain->device->onscreen_depth_stencil = NULL;
|
2010-04-20 22:38:41 +02:00
|
|
|
}
|
2008-09-22 14:52:52 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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,
|
2005-06-23 13:05:24 +02:00
|
|
|
};
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2011-04-07 18:45:58 +02:00
|
|
|
/* Helper function that blits the front buffer contents to the target window. */
|
2011-07-11 22:04:31 +02:00
|
|
|
void x11_copy_to_screen(const struct wined3d_swapchain *swapchain, const RECT *rect)
|
2011-04-07 18:45:58 +02:00
|
|
|
{
|
2014-01-14 13:59:23 +01:00
|
|
|
struct wined3d_surface *front;
|
2011-04-07 18:45:58 +02:00
|
|
|
POINT offset = {0, 0};
|
|
|
|
HDC src_dc, dst_dc;
|
|
|
|
RECT draw_rect;
|
|
|
|
HWND window;
|
|
|
|
|
|
|
|
TRACE("swapchain %p, rect %s.\n", swapchain, wine_dbgstr_rect(rect));
|
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
front = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0));
|
2014-06-28 10:49:32 +02:00
|
|
|
if (swapchain->palette)
|
2014-08-20 13:20:02 +02:00
|
|
|
wined3d_palette_apply_to_dc(swapchain->palette, front->hDC);
|
2014-06-28 10:49:32 +02:00
|
|
|
|
2012-05-21 20:48:34 +02:00
|
|
|
if (front->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);
|
|
|
|
|
2015-10-15 22:41:12 +02:00
|
|
|
surface_load_location(front, NULL, WINED3D_LOCATION_DIB);
|
2014-01-14 13:59:21 +01:00
|
|
|
|
2011-04-07 18:45:58 +02:00
|
|
|
src_dc = front->hDC;
|
|
|
|
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. */
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain->desc.windowed)
|
2011-04-07 18:45:58 +02:00
|
|
|
ClientToScreen(window, &offset);
|
|
|
|
|
|
|
|
TRACE("offset %s.\n", wine_dbgstr_point(&offset));
|
|
|
|
|
|
|
|
draw_rect.left = 0;
|
|
|
|
draw_rect.right = front->resource.width;
|
|
|
|
draw_rect.top = 0;
|
|
|
|
draw_rect.bottom = front->resource.height;
|
|
|
|
|
2011-11-13 19:52:25 +01:00
|
|
|
if (rect)
|
2011-04-07 18:45:58 +02:00
|
|
|
IntersectRect(&draw_rect, &draw_rect, rect);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-04-15 18:57:13 +02:00
|
|
|
static void swapchain_gdi_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in,
|
2011-04-13 19:14:30 +02:00
|
|
|
const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
|
2011-04-07 18:45:58 +02:00
|
|
|
{
|
2011-04-29 13:03:42 +02:00
|
|
|
struct wined3d_surface *front, *back;
|
2011-04-07 18:45:58 +02:00
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
front = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0));
|
2014-08-20 13:20:03 +02:00
|
|
|
back = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->back_buffers[0], 0));
|
2011-04-07 18:45:58 +02:00
|
|
|
|
|
|
|
/* Flip the DC. */
|
|
|
|
{
|
|
|
|
HDC tmp;
|
|
|
|
tmp = front->hDC;
|
|
|
|
front->hDC = back->hDC;
|
|
|
|
back->hDC = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the DIBsection. */
|
|
|
|
{
|
|
|
|
HBITMAP tmp;
|
|
|
|
tmp = front->dib.DIBsection;
|
|
|
|
front->dib.DIBsection = back->dib.DIBsection;
|
|
|
|
back->dib.DIBsection = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the surface data. */
|
|
|
|
{
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
tmp = front->dib.bitmap_data;
|
|
|
|
front->dib.bitmap_data = back->dib.bitmap_data;
|
|
|
|
back->dib.bitmap_data = tmp;
|
|
|
|
|
2013-08-21 15:15:48 +02:00
|
|
|
if (front->resource.heap_memory)
|
2011-04-07 18:45:58 +02:00
|
|
|
ERR("GDI Surface %p has heap memory allocated.\n", front);
|
|
|
|
|
2013-08-21 15:15:48 +02:00
|
|
|
if (back->resource.heap_memory)
|
2011-04-07 18:45:58 +02:00
|
|
|
ERR("GDI Surface %p has heap memory allocated.\n", back);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FPS support */
|
|
|
|
if (TRACE_ON(fps))
|
|
|
|
{
|
|
|
|
static LONG prev_time, frames;
|
|
|
|
DWORD time = GetTickCount();
|
|
|
|
|
|
|
|
++frames;
|
|
|
|
|
|
|
|
/* every 1.5 seconds */
|
|
|
|
if (time - prev_time > 1500)
|
|
|
|
{
|
|
|
|
TRACE_(fps)("@ approx %.2ffps\n", 1000.0 * frames / (time - prev_time));
|
|
|
|
prev_time = time;
|
|
|
|
frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x11_copy_to_screen(swapchain, NULL);
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:30 +02:00
|
|
|
static const struct wined3d_swapchain_ops swapchain_gdi_ops =
|
2011-04-07 18:45:58 +02:00
|
|
|
{
|
2011-04-13 19:14:30 +02:00
|
|
|
swapchain_gdi_present,
|
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
|
|
|
{
|
|
|
|
RECT client_rect;
|
|
|
|
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
|
|
|
|
return;
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!swapchain->desc.backbuffer_count)
|
2011-08-22 21:02:47 +02:00
|
|
|
{
|
|
|
|
TRACE("Single buffered rendering.\n");
|
|
|
|
swapchain->render_to_fbo = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetClientRect(swapchain->win_handle, &client_rect);
|
|
|
|
|
|
|
|
TRACE("Backbuffer %ux%u, window %ux%u.\n",
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.backbuffer_width,
|
|
|
|
swapchain->desc.backbuffer_height,
|
2011-08-22 21:02:47 +02:00
|
|
|
client_rect.right, client_rect.bottom);
|
2011-08-25 21:05:03 +02:00
|
|
|
TRACE("Multisample type %#x, quality %#x.\n",
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc.multisample_type,
|
|
|
|
swapchain->desc.multisample_quality);
|
2011-08-22 21:02:47 +02:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!wined3d_settings.always_offscreen && !swapchain->desc.multisample_type
|
|
|
|
&& swapchain->desc.backbuffer_width == client_rect.right
|
|
|
|
&& swapchain->desc.backbuffer_height == client_rect.bottom)
|
2011-08-22 21:02:47 +02:00
|
|
|
{
|
|
|
|
TRACE("Backbuffer dimensions match window dimensions, rendering onscreen.\n");
|
|
|
|
swapchain->render_to_fbo = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Rendering to FBO.\n");
|
|
|
|
swapchain->render_to_fbo = TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-16 08:51:49 +01:00
|
|
|
static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3d_device *device,
|
|
|
|
struct wined3d_swapchain_desc *desc, void *parent, const struct wined3d_parent_ops *parent_ops)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
const struct wined3d_adapter *adapter = device->adapter;
|
2015-09-03 20:56:26 +02:00
|
|
|
struct wined3d_resource_desc texture_desc;
|
2014-08-20 13:20:02 +02:00
|
|
|
struct wined3d_surface *front_buffer;
|
2009-12-10 21:41:54 +01:00
|
|
|
BOOL displaymode_set = FALSE;
|
|
|
|
RECT client_rect;
|
|
|
|
HWND window;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2013-01-16 08:51:49 +01:00
|
|
|
if (device->wined3d->flags & WINED3D_NO3D)
|
|
|
|
swapchain->swapchain_ops = &swapchain_gdi_ops;
|
|
|
|
else
|
|
|
|
swapchain->swapchain_ops = &swapchain_gl_ops;
|
2009-12-10 21:41:54 +01:00
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
window = desc->device_window ? desc->device_window : device->create_parms.focus_window;
|
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;
|
2010-03-15 21:07:30 +01:00
|
|
|
swapchain->device_window = window;
|
2009-12-10 21:41:54 +01:00
|
|
|
|
2013-08-20 10:20:09 +02:00
|
|
|
if (FAILED(hr = wined3d_get_adapter_display_mode(device->wined3d,
|
|
|
|
adapter->ordinal, &swapchain->original_mode, NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get current display mode, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
2009-12-10 21:41:54 +01:00
|
|
|
|
|
|
|
GetClientRect(window, &client_rect);
|
2011-12-02 08:15:52 +01:00
|
|
|
if (desc->windowed
|
|
|
|
&& (!desc->backbuffer_width || !desc->backbuffer_height
|
|
|
|
|| desc->backbuffer_format == WINED3DFMT_UNKNOWN))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!desc->backbuffer_width)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
desc->backbuffer_width = client_rect.right;
|
|
|
|
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
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
desc->backbuffer_height = client_rect.bottom;
|
|
|
|
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
|
|
|
{
|
2013-08-20 10:20:09 +02:00
|
|
|
desc->backbuffer_format = swapchain->original_mode.format_id;
|
|
|
|
TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->original_mode.format_id));
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-02 08:15:52 +01:00
|
|
|
swapchain->desc = *desc;
|
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;
|
2015-09-03 20:56:26 +02:00
|
|
|
texture_desc.format = swapchain->desc.backbuffer_format;
|
|
|
|
texture_desc.multisample_type = swapchain->desc.multisample_type;
|
|
|
|
texture_desc.multisample_quality = swapchain->desc.multisample_quality;
|
|
|
|
texture_desc.usage = 0;
|
|
|
|
texture_desc.pool = WINED3D_POOL_DEFAULT;
|
|
|
|
texture_desc.width = swapchain->desc.backbuffer_width;
|
|
|
|
texture_desc.height = swapchain->desc.backbuffer_height;
|
|
|
|
texture_desc.depth = 1;
|
|
|
|
texture_desc.size = 0;
|
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,
|
|
|
|
parent, &texture_desc, &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);
|
2015-09-03 20:56:26 +02:00
|
|
|
front_buffer = surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0));
|
2013-01-16 08:51:49 +01:00
|
|
|
if (!(device->wined3d->flags & WINED3D_NO3D))
|
2013-09-10 09:32:34 +02:00
|
|
|
{
|
2014-08-20 13:20:02 +02:00
|
|
|
surface_validate_location(front_buffer, WINED3D_LOCATION_DRAWABLE);
|
|
|
|
surface_invalidate_location(front_buffer, ~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? */
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (!desc->windowed)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
/* Change the display settings */
|
2014-11-18 21:26:57 +01:00
|
|
|
swapchain->d3d_mode.width = desc->backbuffer_width;
|
|
|
|
swapchain->d3d_mode.height = desc->backbuffer_height;
|
|
|
|
swapchain->d3d_mode.format_id = desc->backbuffer_format;
|
|
|
|
swapchain->d3d_mode.refresh_rate = desc->refresh_rate;
|
|
|
|
swapchain->d3d_mode.scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
|
2009-12-10 21:41:54 +01:00
|
|
|
|
2014-11-18 21:26:57 +01:00
|
|
|
if (FAILED(hr = wined3d_set_adapter_display_mode(device->wined3d, adapter->ordinal, &swapchain->d3d_mode)))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to set display mode, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
displaymode_set = TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-16 08:51:49 +01:00
|
|
|
if (!(device->wined3d->flags & WINED3D_NO3D))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2010-08-23 18:28:10 +02:00
|
|
|
static const enum wined3d_format_id formats[] =
|
2010-04-30 16:44:29 +02:00
|
|
|
{
|
|
|
|
WINED3DFMT_D24_UNORM_S8_UINT,
|
|
|
|
WINED3DFMT_D32_UNORM,
|
|
|
|
WINED3DFMT_R24_UNORM_X8_TYPELESS,
|
|
|
|
WINED3DFMT_D16_UNORM,
|
|
|
|
WINED3DFMT_S1_UINT_D15_UNORM
|
|
|
|
};
|
|
|
|
|
2013-08-19 10:50:52 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &adapter->gl_info;
|
2010-03-28 16:25:04 +02:00
|
|
|
|
2011-10-16 23:11:48 +02:00
|
|
|
swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
|
2011-04-08 14:30:59 +02:00
|
|
|
if (!swapchain->context)
|
|
|
|
{
|
|
|
|
ERR("Failed to create the context array.\n");
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
swapchain->num_contexts = 1;
|
|
|
|
|
2010-03-28 16:25:04 +02:00
|
|
|
/* In WGL both color, depth and stencil are features of a pixel format. In case of D3D they are separate.
|
|
|
|
* You are able to add a depth + stencil surface at a later stage when you need it.
|
|
|
|
* In order to support this properly in WineD3D we need the ability to recreate the opengl context and
|
|
|
|
* drawable when this is required. This is very tricky as we need to reapply ALL opengl states for the new
|
|
|
|
* context, need torecreate shaders, textures and other resources.
|
|
|
|
*
|
|
|
|
* The context manager already takes care of the state problem and for the other tasks code from Reset
|
|
|
|
* can be used. These changes are way to risky during the 1.0 code freeze which is taking place right now.
|
|
|
|
* Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the
|
|
|
|
* time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
|
|
|
|
* issue needs to be fixed. */
|
2010-04-30 16:44:29 +02:00
|
|
|
for (i = 0; i < (sizeof(formats) / sizeof(*formats)); i++)
|
2010-03-28 16:25:04 +02:00
|
|
|
{
|
2010-08-30 20:29:49 +02:00
|
|
|
swapchain->ds_format = wined3d_get_format(gl_info, formats[i]);
|
2014-08-20 13:20:02 +02:00
|
|
|
swapchain->context[0] = context_create(swapchain, front_buffer, swapchain->ds_format);
|
2010-04-30 16:44:29 +02:00
|
|
|
if (swapchain->context[0]) break;
|
|
|
|
TRACE("Depth stencil format %s is not supported, trying next format\n",
|
|
|
|
debug_d3dformat(formats[i]));
|
2010-03-28 16:25:04 +02:00
|
|
|
}
|
2010-04-30 16:44:29 +02:00
|
|
|
|
2010-03-28 16:25:04 +02:00
|
|
|
if (!swapchain->context[0])
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create context.\n");
|
|
|
|
hr = WINED3DERR_NOTAVAILABLE;
|
|
|
|
goto err;
|
|
|
|
}
|
2010-04-30 16:44:29 +02:00
|
|
|
|
2011-09-12 19:51:17 +02:00
|
|
|
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
|
2011-12-02 08:15:52 +01:00
|
|
|
&& (!desc->enable_auto_depth_stencil
|
|
|
|
|| swapchain->desc.auto_depth_stencil_format != swapchain->ds_format->id))
|
2010-04-30 16:44:29 +02:00
|
|
|
{
|
|
|
|
FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n");
|
|
|
|
}
|
2009-12-15 17:51:37 +01:00
|
|
|
context_release(swapchain->context[0]);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
if (swapchain->desc.backbuffer_count > 0)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2010-04-26 21:33:01 +02:00
|
|
|
swapchain->back_buffers = HeapAlloc(GetProcessHeap(), 0,
|
2011-12-02 08:15:52 +01:00
|
|
|
sizeof(*swapchain->back_buffers) * swapchain->desc.backbuffer_count);
|
2010-04-26 21:33:01 +02:00
|
|
|
if (!swapchain->back_buffers)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate backbuffer array memory.\n");
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
texture_desc.usage |= WINED3DUSAGE_RENDERTARGET;
|
2011-12-02 08:15:52 +01:00
|
|
|
for (i = 0; i < swapchain->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,
|
|
|
|
parent, &texture_desc, &swapchain->back_buffers[i])))
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
|
2014-01-08 10:56:15 +01:00
|
|
|
swapchain->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. */
|
2013-01-16 08:51:49 +01:00
|
|
|
if (desc->enable_auto_depth_stencil && !(device->wined3d->flags & WINED3D_NO3D))
|
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
|
|
|
{
|
2015-09-03 20:56:26 +02:00
|
|
|
struct wined3d_texture *ds;
|
|
|
|
struct wined3d_rendertarget_view_desc desc;
|
2014-08-22 12:32:01 +02:00
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
texture_desc.format = swapchain->desc.auto_depth_stencil_format;
|
|
|
|
texture_desc.usage = WINED3DUSAGE_DEPTHSTENCIL;
|
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,
|
|
|
|
device->device_parent, &texture_desc, &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;
|
|
|
|
desc.u.texture.level_idx = 0;
|
|
|
|
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
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (displaymode_set)
|
|
|
|
{
|
2013-08-20 10:20:09 +02:00
|
|
|
if (FAILED(wined3d_set_adapter_display_mode(device->wined3d,
|
|
|
|
adapter->ordinal, &swapchain->original_mode)))
|
|
|
|
ERR("Failed to restore display mode.\n");
|
2009-12-10 21:41:54 +01:00
|
|
|
ClipCursor(NULL);
|
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (swapchain->back_buffers)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2011-12-02 08:15:52 +01:00
|
|
|
for (i = 0; i < swapchain->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
|
|
|
}
|
2010-04-26 21:33:01 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->back_buffers);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
|
2010-01-19 23:52:25 +01:00
|
|
|
if (swapchain->context)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2010-01-19 23:52:25 +01:00
|
|
|
if (swapchain->context[0])
|
|
|
|
{
|
|
|
|
context_release(swapchain->context[0]);
|
|
|
|
context_destroy(device, swapchain->context[0]);
|
|
|
|
swapchain->num_contexts = 0;
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
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
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2013-01-16 08:51:49 +01:00
|
|
|
HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device, struct wined3d_swapchain_desc *desc,
|
|
|
|
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;
|
|
|
|
|
2013-01-16 08:51:49 +01:00
|
|
|
TRACE("device %p, desc %p, parent %p, parent_ops %p, swapchain %p.\n",
|
|
|
|
device, desc, parent, parent_ops, swapchain);
|
2011-05-10 21:18:47 +02:00
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2013-01-16 08:51:49 +01:00
|
|
|
hr = swapchain_init(object, device, desc, parent, parent_ops);
|
2011-05-10 21:18:47 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize swapchain, hr %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created swapchain %p.\n", object);
|
|
|
|
*swapchain = object;
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
static struct wined3d_context *swapchain_create_context(struct wined3d_swapchain *swapchain)
|
2009-08-03 08:06:51 +02:00
|
|
|
{
|
|
|
|
struct wined3d_context **newArray;
|
|
|
|
struct wined3d_context *ctx;
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2011-01-18 17:55:21 +01:00
|
|
|
TRACE("Creating a new context for swapchain %p, thread %u.\n", swapchain, GetCurrentThreadId());
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2014-08-20 13:20:02 +02:00
|
|
|
if (!(ctx = context_create(swapchain,
|
|
|
|
surface_from_resource(wined3d_texture_get_sub_resource(swapchain->front_buffer, 0)),
|
|
|
|
swapchain->ds_format)))
|
2009-10-28 11:00:12 +01:00
|
|
|
{
|
2007-06-02 22:21:57 +02:00
|
|
|
ERR("Failed to create a new context for the swapchain\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-28 11:00:12 +01:00
|
|
|
context_release(ctx);
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2011-01-18 17:55:21 +01:00
|
|
|
newArray = HeapAlloc(GetProcessHeap(), 0, sizeof(*newArray) * (swapchain->num_contexts + 1));
|
2007-06-02 22:21:57 +02:00
|
|
|
if(!newArray) {
|
|
|
|
ERR("Out of memory when trying to allocate a new context array\n");
|
2011-01-18 17:55:21 +01:00
|
|
|
context_destroy(swapchain->device, ctx);
|
2007-06-02 22:21:57 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-01-18 17:55:21 +01:00
|
|
|
memcpy(newArray, swapchain->context, sizeof(*newArray) * swapchain->num_contexts);
|
|
|
|
HeapFree(GetProcessHeap(), 0, swapchain->context);
|
|
|
|
newArray[swapchain->num_contexts] = ctx;
|
|
|
|
swapchain->context = newArray;
|
|
|
|
swapchain->num_contexts++;
|
2007-06-02 22:21:57 +02:00
|
|
|
|
|
|
|
TRACE("Returning context %p\n", ctx);
|
|
|
|
return ctx;
|
|
|
|
}
|
2007-11-30 20:22:33 +01:00
|
|
|
|
2011-06-28 02:26:20 +02:00
|
|
|
void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < swapchain->num_contexts; ++i)
|
|
|
|
{
|
|
|
|
context_destroy(swapchain->device, swapchain->context[i]);
|
|
|
|
}
|
|
|
|
swapchain->num_contexts = 0;
|
|
|
|
}
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
struct wined3d_context *swapchain_get_context(struct wined3d_swapchain *swapchain)
|
2011-01-19 19:20:11 +01:00
|
|
|
{
|
|
|
|
DWORD tid = GetCurrentThreadId();
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < swapchain->num_contexts; ++i)
|
|
|
|
{
|
|
|
|
if (swapchain->context[i]->tid == tid)
|
|
|
|
return swapchain->context[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new context for the thread */
|
|
|
|
return swapchain_create_context(swapchain);
|
|
|
|
}
|
|
|
|
|
2011-07-05 22:30:53 +02:00
|
|
|
HDC swapchain_get_backup_dc(struct wined3d_swapchain *swapchain)
|
|
|
|
{
|
|
|
|
if (!swapchain->backup_dc)
|
|
|
|
{
|
|
|
|
TRACE("Creating the backup window for swapchain %p.\n", swapchain);
|
|
|
|
|
|
|
|
if (!(swapchain->backup_wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
|
|
|
|
WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL)))
|
|
|
|
{
|
|
|
|
ERR("Failed to create a window.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(swapchain->backup_dc = GetDC(swapchain->backup_wnd)))
|
|
|
|
{
|
|
|
|
ERR("Failed to get a DC.\n");
|
|
|
|
DestroyWindow(swapchain->backup_wnd);
|
|
|
|
swapchain->backup_wnd = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return swapchain->backup_dc;
|
|
|
|
}
|
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
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
for (i = 0; i < swapchain->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;
|
|
|
|
BOOL filter_messages = device->filter_messages;
|
|
|
|
|
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. */
|
|
|
|
|
2014-12-04 21:51:49 +01:00
|
|
|
device->filter_messages = !(device->wined3d->flags & WINED3D_FOCUS_MESSAGES);
|
|
|
|
|
2014-11-18 21:26:57 +01:00
|
|
|
if (activate)
|
|
|
|
{
|
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. */
|
|
|
|
SetWindowPos(swapchain->device_window, NULL, 0, 0,
|
|
|
|
swapchain->desc.backbuffer_width, swapchain->desc.backbuffer_height,
|
|
|
|
SWP_NOACTIVATE | SWP_NOZORDER);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-12-04 21:51:49 +01:00
|
|
|
if (FAILED(wined3d_set_adapter_display_mode(device->wined3d,
|
|
|
|
device->adapter->ordinal, &swapchain->d3d_mode)))
|
2014-11-18 21:26:57 +01:00
|
|
|
ERR("Failed to set display mode.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-04 21:51:49 +01:00
|
|
|
if (FAILED(wined3d_set_adapter_display_mode(device->wined3d,
|
|
|
|
device->adapter->ordinal, NULL)))
|
2014-11-18 21:26:57 +01:00
|
|
|
ERR("Failed to set display mode.\n");
|
|
|
|
|
|
|
|
swapchain->reapply_mode = TRUE;
|
|
|
|
|
2014-12-04 21:51:49 +01:00
|
|
|
if (!(device->create_parms.flags & WINED3DCREATE_NOWINDOWCHANGES)
|
2014-11-19 20:13:52 +01:00
|
|
|
&& IsWindowVisible(swapchain->device_window))
|
2014-11-18 21:26:57 +01:00
|
|
|
ShowWindow(swapchain->device_window, SW_MINIMIZE);
|
|
|
|
}
|
2014-12-04 21:51:49 +01:00
|
|
|
|
|
|
|
device->filter_messages = filter_messages;
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (buffer_count && buffer_count != swapchain->desc.backbuffer_count)
|
|
|
|
FIXME("Cannot change the back buffer count yet.\n");
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!swapchain->desc.windowed)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
|
|
|
|
if (!GetClientRect(swapchain->device_window, &client_rect))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width != swapchain->desc.backbuffer_width
|
|
|
|
|| height != swapchain->desc.backbuffer_height)
|
|
|
|
{
|
|
|
|
swapchain->desc.backbuffer_width = width;
|
|
|
|
swapchain->desc.backbuffer_height = height;
|
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format_id == WINED3DFMT_UNKNOWN)
|
|
|
|
{
|
|
|
|
if (!swapchain->desc.windowed)
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
format_id = swapchain->original_mode.format_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format_id != swapchain->desc.backbuffer_format)
|
|
|
|
{
|
|
|
|
swapchain->desc.backbuffer_format = format_id;
|
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (multisample_type != swapchain->desc.multisample_type
|
|
|
|
|| multisample_quality != swapchain->desc.multisample_quality)
|
|
|
|
{
|
|
|
|
swapchain->desc.multisample_type = multisample_type;
|
|
|
|
swapchain->desc.multisample_quality = multisample_quality;
|
|
|
|
update_desc = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_desc)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (FAILED(hr = wined3d_texture_update_desc(swapchain->front_buffer, swapchain->desc.backbuffer_width,
|
|
|
|
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
|
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
for (i = 0; i < swapchain->desc.backbuffer_count; ++i)
|
|
|
|
{
|
|
|
|
if (FAILED(hr = wined3d_texture_update_desc(swapchain->back_buffers[i], swapchain->desc.backbuffer_width,
|
|
|
|
swapchain->desc.backbuffer_height, swapchain->desc.backbuffer_format,
|
|
|
|
swapchain->desc.multisample_type, swapchain->desc.multisample_quality, NULL, 0)))
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
swapchain_update_render_to_fbo(swapchain);
|
|
|
|
swapchain_update_draw_bindings(swapchain);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|