2005-06-23 13:05:24 +02:00
|
|
|
/*
|
|
|
|
*IDirect3DSwapChain9 implementation
|
|
|
|
*
|
|
|
|
*Copyright 2002-2003 Jason Edmeades
|
|
|
|
*Copyright 2002-2003 Raphael Junqueira
|
|
|
|
*Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
*Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2005-06-23 13:05:24 +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.
|
|
|
|
*
|
|
|
|
*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.
|
|
|
|
*
|
|
|
|
*You should have received a copy of the GNU Lesser General Public
|
|
|
|
*License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
*Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-23 13:05:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
|
2005-07-13 16:15:54 +02:00
|
|
|
/*TODO: some of the additional parameters may be required to
|
2005-06-23 13:05:24 +02:00
|
|
|
set the gamma ramp (for some weird reason microsoft have left swap gammaramp in device
|
|
|
|
but it operates on a swapchain, it may be a good idea to move it to IWineD3DSwapChain for IWineD3D)*/
|
2005-07-13 16:15:54 +02:00
|
|
|
|
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
2006-07-05 18:35:21 +02:00
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(fps);
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2009-09-16 08:37:15 +02:00
|
|
|
static void WINAPI IWineD3DSwapChainImpl_Destroy(IWineD3DSwapChain *iface)
|
|
|
|
{
|
2006-12-05 00:29:14 +01:00
|
|
|
IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
2007-02-15 13:53:33 +01:00
|
|
|
WINED3DDISPLAYMODE mode;
|
2008-12-01 23:19:43 +01:00
|
|
|
unsigned int i;
|
2006-12-05 00:29:14 +01:00
|
|
|
|
2008-07-01 18:17:38 +02:00
|
|
|
TRACE("Destroying swapchain %p\n", iface);
|
|
|
|
|
|
|
|
IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
/* Release the swapchain's draw buffers. Make sure This->back_buffers[0] is
|
2009-08-12 09:44:22 +02:00
|
|
|
* the last buffer to be destroyed, FindContext() depends on that. */
|
2010-04-26 21:33:00 +02:00
|
|
|
if (This->front_buffer)
|
2009-08-12 09:44:22 +02:00
|
|
|
{
|
2010-08-16 20:00:25 +02:00
|
|
|
surface_set_container(This->front_buffer, WINED3D_CONTAINER_NONE, NULL);
|
2010-04-26 21:33:00 +02:00
|
|
|
if (IWineD3DSurface_Release((IWineD3DSurface *)This->front_buffer))
|
2009-08-12 09:44:22 +02:00
|
|
|
{
|
2009-09-16 08:37:15 +02:00
|
|
|
WARN("(%p) Something's still holding the front buffer (%p).\n",
|
2010-04-26 21:33:00 +02:00
|
|
|
This, This->front_buffer);
|
2006-12-05 00:29:14 +01:00
|
|
|
}
|
2010-04-26 21:33:00 +02:00
|
|
|
This->front_buffer = NULL;
|
2006-12-05 00:29:14 +01:00
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (This->back_buffers)
|
2009-08-12 09:44:22 +02:00
|
|
|
{
|
|
|
|
UINT i = This->presentParms.BackBufferCount;
|
|
|
|
|
|
|
|
while (i--)
|
|
|
|
{
|
2010-08-16 20:00:25 +02:00
|
|
|
surface_set_container(This->back_buffers[i], WINED3D_CONTAINER_NONE, NULL);
|
2010-04-26 21:33:01 +02:00
|
|
|
if (IWineD3DSurface_Release((IWineD3DSurface *)This->back_buffers[i]))
|
2009-09-16 08:37:15 +02:00
|
|
|
WARN("(%p) Something's still holding back buffer %u (%p).\n",
|
2010-04-26 21:33:01 +02:00
|
|
|
This, i, This->back_buffers[i]);
|
2006-12-05 00:29:14 +01:00
|
|
|
}
|
2010-04-26 21:33:01 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->back_buffers);
|
|
|
|
This->back_buffers = NULL;
|
2006-12-05 00:29:14 +01:00
|
|
|
}
|
|
|
|
|
2009-07-08 09:49:26 +02:00
|
|
|
for (i = 0; i < This->num_contexts; ++i)
|
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
context_destroy(This->device, This->context[i]);
|
2007-11-14 22:45:00 +01:00
|
|
|
}
|
2007-02-15 13:53:33 +01: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
|
|
|
|
*/
|
2010-09-14 13:38:40 +02:00
|
|
|
if (!This->presentParms.Windowed && This->presentParms.AutoRestoreDisplayMode)
|
|
|
|
{
|
2007-02-15 13:53:33 +01:00
|
|
|
mode.Width = This->orig_width;
|
|
|
|
mode.Height = This->orig_height;
|
|
|
|
mode.RefreshRate = 0;
|
|
|
|
mode.Format = This->orig_fmt;
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)This->device, 0, &mode);
|
2007-02-15 13:53:33 +01:00
|
|
|
}
|
2007-02-12 19:22:41 +01:00
|
|
|
|
2009-12-14 20:49:52 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->context);
|
2006-12-05 00:29:14 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
2009-12-06 17:39:47 +01:00
|
|
|
/* A GL context is provided by the caller */
|
2010-01-03 21:18:25 +01:00
|
|
|
static void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context *context,
|
|
|
|
const RECT *src_rect, const RECT *dst_rect)
|
2009-12-06 17:39:47 +01:00
|
|
|
{
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl *device = This->device;
|
2010-04-26 21:33:01 +02:00
|
|
|
IWineD3DSurfaceImpl *backbuffer = This->back_buffers[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",
|
|
|
|
This, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-05-18 09:53:09 +02:00
|
|
|
GetClientRect(This->win_handle, &win_rect);
|
|
|
|
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
|
|
|
{
|
|
|
|
ENTER_GL();
|
2010-07-26 12:06:32 +02:00
|
|
|
context_apply_fbo_state_blit(context, GL_READ_FRAMEBUFFER, backbuffer, NULL, SFLAG_INTEXTURE);
|
2010-05-05 18:22:36 +02:00
|
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
|
2009-12-13 22:04:01 +01:00
|
|
|
context_set_draw_buffer(context, GL_BACK);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2010-07-21 18:48:24 +02:00
|
|
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE));
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE1));
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE2));
|
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(device, STATE_RENDER(WINED3DRS_COLORWRITEENABLE3));
|
|
|
|
|
2009-12-06 17:39:47 +01:00
|
|
|
glDisable(GL_SCISSOR_TEST);
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDeviceImpl_MarkStateDirty(This->device, STATE_RENDER(WINED3DRS_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");
|
|
|
|
LEAVE_GL();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context2 = context_acquire(This->device, This->back_buffers[0]);
|
|
|
|
context_apply_blit_state(context2, device);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (backbuffer->flags & SFLAG_NORMCOORD)
|
2009-12-06 17:39:47 +01:00
|
|
|
{
|
2010-01-03 21:18:25 +01:00
|
|
|
tex_left /= src_w;
|
|
|
|
tex_right /= src_w;
|
|
|
|
tex_top /= src_h;
|
|
|
|
tex_bottom /= src_h;
|
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;
|
|
|
|
|
2009-12-06 17:39:47 +01:00
|
|
|
ENTER_GL();
|
2010-09-08 11:24:46 +02:00
|
|
|
context_bind_fbo(context2, GL_FRAMEBUFFER, NULL);
|
2009-12-06 17:39:47 +01:00
|
|
|
|
|
|
|
/* Set up the texture. The surface is not in a IWineD3D*Texture container,
|
|
|
|
* so there are no d3d texture settings to dirtify
|
|
|
|
*/
|
2010-12-09 23:41:18 +01:00
|
|
|
device->blitter->set_shader(device->blit_priv, context2->gl_info, backbuffer);
|
2010-03-16 19:02:13 +01:00
|
|
|
glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter);
|
|
|
|
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. */
|
2009-12-06 17:39:47 +01:00
|
|
|
glPushAttrib(GL_VIEWPORT_BIT);
|
2010-05-18 09:53:09 +02:00
|
|
|
glViewport(dst_rect->left, win_h - dst_rect->bottom, dst_rect->right, win_h - dst_rect->top);
|
2009-12-06 17:39:47 +01:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
/* bottom left */
|
|
|
|
glTexCoord2f(tex_left, tex_bottom);
|
|
|
|
glVertex2i(-1, -1);
|
|
|
|
|
|
|
|
/* top left */
|
|
|
|
glTexCoord2f(tex_left, tex_top);
|
|
|
|
glVertex2i(-1, 1);
|
|
|
|
|
|
|
|
/* top right */
|
|
|
|
glTexCoord2f(tex_right, tex_top);
|
|
|
|
glVertex2i(1, 1);
|
|
|
|
|
|
|
|
/* bottom right */
|
|
|
|
glTexCoord2f(tex_right, tex_bottom);
|
|
|
|
glVertex2i(1, -1);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
glPopAttrib();
|
|
|
|
|
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");
|
|
|
|
LEAVE_GL();
|
|
|
|
|
|
|
|
context_release(context2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-18 20:50:40 +01:00
|
|
|
static HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface,
|
|
|
|
const RECT *pSourceRect, const RECT *pDestRect, HWND hDestWindowOverride,
|
|
|
|
const RGNDATA *pDirtyRegion, DWORD flags)
|
|
|
|
{
|
2005-06-23 13:05:24 +02:00
|
|
|
IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
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;
|
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
|
|
|
|
2010-02-04 18:30:07 +01:00
|
|
|
IWineD3DSwapChain_SetDestWindowOverride(iface, hDestWindowOverride);
|
|
|
|
|
2010-05-03 22:03:28 +02:00
|
|
|
context = context_acquire(This->device, This->back_buffers[0]);
|
2010-03-17 21:59:54 +01:00
|
|
|
if (!context->valid)
|
|
|
|
{
|
|
|
|
context_release(context);
|
|
|
|
WARN("Invalid context, skipping present.\n");
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
2007-03-17 23:00:39 +01:00
|
|
|
|
2010-05-24 09:56:35 +02:00
|
|
|
gl_info = context->gl_info;
|
|
|
|
|
2006-07-23 00:03:33 +02:00
|
|
|
/* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
|
2009-12-09 20:32:08 +01:00
|
|
|
if (This->device->bCursorVisible && This->device->cursorTexture)
|
|
|
|
{
|
2006-07-27 17:39:03 +02:00
|
|
|
IWineD3DSurfaceImpl cursor;
|
2009-12-09 20:32:08 +01:00
|
|
|
RECT destRect =
|
|
|
|
{
|
|
|
|
This->device->xScreenSpace - This->device->xHotSpot,
|
|
|
|
This->device->yScreenSpace - This->device->yHotSpot,
|
|
|
|
This->device->xScreenSpace + This->device->cursorWidth - This->device->xHotSpot,
|
|
|
|
This->device->yScreenSpace + This->device->cursorHeight - This->device->yHotSpot,
|
|
|
|
};
|
2006-07-27 17:39:03 +02:00
|
|
|
TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor);
|
|
|
|
/* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
|
|
|
|
* the application because we are only supposed to copy the information out. Using a fake surface
|
|
|
|
* allows to use the Blitting engine and avoid copying the whole texture -> render target blitting code.
|
|
|
|
*/
|
|
|
|
memset(&cursor, 0, sizeof(cursor));
|
|
|
|
cursor.lpVtbl = &IWineD3DSurface_Vtbl;
|
|
|
|
cursor.resource.ref = 1;
|
2009-12-09 20:32:08 +01:00
|
|
|
cursor.resource.device = This->device;
|
2006-07-27 17:39:03 +02:00
|
|
|
cursor.resource.pool = WINED3DPOOL_SCRATCH;
|
2010-08-30 20:29:49 +02:00
|
|
|
cursor.resource.format = wined3d_get_format(gl_info, WINED3DFMT_B8G8R8A8_UNORM);
|
2006-07-27 17:39:03 +02:00
|
|
|
cursor.resource.resourceType = WINED3DRTYPE_SURFACE;
|
2009-12-09 20:32:08 +01:00
|
|
|
cursor.texture_name = This->device->cursorTexture;
|
2009-07-10 10:20:13 +02:00
|
|
|
cursor.texture_target = GL_TEXTURE_2D;
|
|
|
|
cursor.texture_level = 0;
|
2011-03-08 19:41:07 +01:00
|
|
|
cursor.resource.width = This->device->cursorWidth;
|
|
|
|
cursor.resource.height = This->device->cursorHeight;
|
2006-07-27 17:39:03 +02:00
|
|
|
/* The cursor must have pow2 sizes */
|
2011-03-08 19:41:07 +01:00
|
|
|
cursor.pow2Width = cursor.resource.width;
|
|
|
|
cursor.pow2Height = cursor.resource.height;
|
2007-03-06 21:47:45 +01:00
|
|
|
/* The surface is in the texture */
|
2010-11-12 13:12:04 +01:00
|
|
|
cursor.flags |= SFLAG_INTEXTURE;
|
2006-07-23 00:03:33 +02:00
|
|
|
/* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0,
|
|
|
|
* which is exactly what we want :-)
|
|
|
|
*/
|
2006-10-19 18:45:17 +02:00
|
|
|
if (This->presentParms.Windowed) {
|
|
|
|
MapWindowPoints(NULL, This->win_handle, (LPPOINT)&destRect, 2);
|
|
|
|
}
|
2010-04-26 21:33:01 +02:00
|
|
|
IWineD3DSurface_Blt((IWineD3DSurface *)This->back_buffers[0], &destRect, (IWineD3DSurface *)&cursor,
|
2009-08-05 09:01:03 +02:00
|
|
|
NULL, WINEDDBLT_KEYSRC, NULL, WINED3DTEXF_POINT);
|
2006-07-23 00:03:33 +02:00
|
|
|
}
|
2009-12-09 20:32:08 +01:00
|
|
|
|
|
|
|
if (This->device->logo_surface)
|
|
|
|
{
|
|
|
|
/* Blit the logo into the upper left corner of the drawable. */
|
2010-04-26 21:33:01 +02:00
|
|
|
IWineD3DSurface_BltFast((IWineD3DSurface *)This->back_buffers[0], 0, 0,
|
|
|
|
This->device->logo_surface, NULL, WINEDDBLTFAST_SRCCOLORKEY);
|
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
|
|
|
|
2010-01-03 21:18:26 +01:00
|
|
|
render_to_fbo = This->render_to_fbo;
|
|
|
|
|
|
|
|
if (pSourceRect)
|
|
|
|
{
|
|
|
|
src_rect = *pSourceRect;
|
|
|
|
if (!render_to_fbo && (src_rect.left || src_rect.top
|
|
|
|
|| src_rect.right != This->presentParms.BackBufferWidth
|
|
|
|
|| src_rect.bottom != This->presentParms.BackBufferHeight))
|
|
|
|
{
|
|
|
|
render_to_fbo = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src_rect.left = 0;
|
|
|
|
src_rect.top = 0;
|
|
|
|
src_rect.right = This->presentParms.BackBufferWidth;
|
|
|
|
src_rect.bottom = This->presentParms.BackBufferHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pDestRect) dst_rect = *pDestRect;
|
|
|
|
else GetClientRect(This->win_handle, &dst_rect);
|
|
|
|
|
|
|
|
if (!render_to_fbo && (dst_rect.left || dst_rect.top
|
|
|
|
|| dst_rect.right != This->presentParms.BackBufferWidth
|
|
|
|
|| dst_rect.bottom != This->presentParms.BackBufferHeight))
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
2010-01-03 21:18:26 +01:00
|
|
|
if (!This->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
|
2009-11-24 12:31:39 +01:00
|
|
|
{
|
2010-07-21 18:48:22 +02:00
|
|
|
surface_load_location(This->back_buffers[0], SFLAG_INTEXTURE, NULL);
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This->back_buffers[0], SFLAG_INDRAWABLE, FALSE);
|
2010-01-03 21:18:26 +01:00
|
|
|
This->render_to_fbo = TRUE;
|
2009-11-24 12:31:39 +01:00
|
|
|
}
|
|
|
|
|
2009-12-06 17:39:47 +01:00
|
|
|
if(This->render_to_fbo)
|
|
|
|
{
|
|
|
|
/* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer-
|
|
|
|
* window size mismatch is impossible(fullscreen) and src and dst rectangles are
|
|
|
|
* not allowed(they need the COPY swapeffect)
|
|
|
|
*
|
|
|
|
* The DISCARD swap effect is ok as well since any backbuffer content is allowed after
|
|
|
|
* the swap
|
|
|
|
*/
|
|
|
|
if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP )
|
|
|
|
{
|
|
|
|
FIXME("Render-to-fbo with WINED3DSWAPEFFECT_FLIP\n");
|
|
|
|
}
|
2010-01-03 21:18:25 +01:00
|
|
|
|
|
|
|
swapchain_blit(This, context, &src_rect, &dst_rect);
|
2009-12-06 17:39:47 +01:00
|
|
|
}
|
|
|
|
|
2010-01-27 20:19:41 +01:00
|
|
|
if (This->num_contexts > 1) wglFinish();
|
2010-02-04 18:30:08 +01:00
|
|
|
SwapBuffers(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();
|
2007-01-10 11:27:26 +01:00
|
|
|
This->frames++;
|
2005-06-23 13:05:24 +02:00
|
|
|
/* every 1.5 seconds */
|
2007-01-10 11:27:26 +01:00
|
|
|
if (time - This->prev_time > 1500) {
|
|
|
|
TRACE_(fps)("%p @ approx %.2ffps\n", This, 1000.0*This->frames/(time - This->prev_time));
|
|
|
|
This->prev_time = time;
|
|
|
|
This->frames = 0;
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-13 22:13:39 +01:00
|
|
|
/* This is disabled, but the code left in for debug purposes.
|
|
|
|
*
|
|
|
|
* Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip,
|
|
|
|
* we can clear it with some ugly color to make bad drawing visible and ease debugging.
|
|
|
|
* The Debug runtime does the same on Windows. However, a few games do not redraw the
|
|
|
|
* screen properly, like Max Payne 2, which leaves a few pixels undefined.
|
|
|
|
*
|
|
|
|
* Tests show that the content of the back buffer after a discard flip is indeed not
|
|
|
|
* reliable, so no game can depend on the exact content. However, it resembles the
|
|
|
|
* old contents in some way, for example by showing fragments at other locations. In
|
|
|
|
* general, the color theme is still intact. So Max payne, which draws rather dark scenes
|
|
|
|
* gets a dark background image. If we clear it with a bright ugly color, the game's
|
|
|
|
* bug shows up much more than it does on Windows, and the players see single pixels
|
|
|
|
* with wrong colors.
|
|
|
|
* (The Max Payne bug has been confirmed on Windows with the debug runtime)
|
|
|
|
*/
|
|
|
|
if (FALSE && This->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD) {
|
|
|
|
TRACE("Clearing the color buffer with cyan color\n");
|
2005-07-13 16:15:54 +02:00
|
|
|
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDevice_Clear((IWineD3DDevice *)This->device, 0, NULL,
|
2009-07-07 11:08:01 +02:00
|
|
|
WINED3DCLEAR_TARGET, 0xff00ffff, 1.0f, 0);
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
2005-11-17 12:05:12 +01:00
|
|
|
|
2010-11-12 13:12:04 +01:00
|
|
|
if (!This->render_to_fbo && ((This->front_buffer->flags & SFLAG_INSYSMEM)
|
|
|
|
|| (This->back_buffers[0]->flags & SFLAG_INSYSMEM)))
|
2010-04-26 21:33:00 +02:00
|
|
|
{
|
2009-12-06 17:39:47 +01:00
|
|
|
/* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
|
|
|
|
* Doesn't work with render_to_fbo because we're not flipping
|
|
|
|
*/
|
2010-04-26 21:33:00 +02:00
|
|
|
IWineD3DSurfaceImpl *front = This->front_buffer;
|
2010-04-26 21:33:01 +02:00
|
|
|
IWineD3DSurfaceImpl *back = This->back_buffers[0];
|
2006-07-17 23:01:32 +02:00
|
|
|
|
2007-05-28 21:21:43 +02:00
|
|
|
if(front->resource.size == back->resource.size) {
|
2008-07-24 20:38:10 +02:00
|
|
|
DWORD fbflags;
|
2008-07-24 18:38:51 +02:00
|
|
|
flip_surface(front, back);
|
2008-07-24 20:38:10 +02:00
|
|
|
|
|
|
|
/* Tell the front buffer surface that is has been modified. However,
|
|
|
|
* the other locations were preserved during that, so keep the flags.
|
2010-11-12 13:12:04 +01:00
|
|
|
* This serves to update the emulated overlay, if any. */
|
|
|
|
fbflags = front->flags;
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(front, SFLAG_INDRAWABLE, TRUE);
|
2010-11-12 13:12:04 +01:00
|
|
|
front->flags = fbflags;
|
2010-07-21 18:48:21 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
surface_modify_location(front, SFLAG_INDRAWABLE, TRUE);
|
|
|
|
surface_modify_location(back, SFLAG_INDRAWABLE, TRUE);
|
2006-07-17 23:01:32 +02:00
|
|
|
}
|
2010-04-26 21:33:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This->front_buffer, SFLAG_INDRAWABLE, TRUE);
|
2008-07-24 20:38:10 +02:00
|
|
|
/* 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. If it is FLIP however,
|
|
|
|
* the texture / sysmem copy needs to be reloaded from the drawable
|
|
|
|
*/
|
2010-04-26 21:33:01 +02:00
|
|
|
if (This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP)
|
|
|
|
{
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(This->back_buffers[0], SFLAG_INDRAWABLE, TRUE);
|
2008-07-24 20:38:10 +02:00
|
|
|
}
|
2006-07-17 23:01:32 +02:00
|
|
|
}
|
2006-06-04 16:42:57 +02:00
|
|
|
|
2010-04-19 20:47:01 +02:00
|
|
|
if (This->device->depth_stencil)
|
2009-12-09 20:32:08 +01:00
|
|
|
{
|
2008-09-22 14:52:52 +02:00
|
|
|
if (This->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|
2010-11-12 13:12:04 +01:00
|
|
|
|| This->device->depth_stencil->flags & SFLAG_DISCARD)
|
2009-12-09 20:32:08 +01:00
|
|
|
{
|
2010-04-29 00:08:59 +02:00
|
|
|
surface_modify_ds_location(This->device->depth_stencil, SFLAG_DS_DISCARDED,
|
2011-03-08 19:41:07 +01:00
|
|
|
This->device->depth_stencil->resource.width,
|
|
|
|
This->device->depth_stencil->resource.height);
|
2010-04-20 22:38:41 +02:00
|
|
|
if (This->device->depth_stencil == This->device->onscreen_depth_stencil)
|
|
|
|
{
|
|
|
|
IWineD3DSurface_Release((IWineD3DSurface *)This->device->onscreen_depth_stencil);
|
|
|
|
This->device->onscreen_depth_stencil = NULL;
|
|
|
|
}
|
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-11-17 12:05:12 +01:00
|
|
|
TRACE("returning\n");
|
2006-04-07 12:51:12 +02:00
|
|
|
return WINED3D_OK;
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
|
|
|
|
2010-03-15 21:07:31 +01:00
|
|
|
static HRESULT WINAPI IWineD3DSwapChainImpl_SetDestWindowOverride(IWineD3DSwapChain *iface, HWND window)
|
|
|
|
{
|
|
|
|
IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)iface;
|
2008-07-29 05:34:32 +02:00
|
|
|
|
2010-03-15 21:07:31 +01:00
|
|
|
if (!window) window = swapchain->device_window;
|
|
|
|
if (window == swapchain->win_handle) return WINED3D_OK;
|
2008-07-29 05:34:32 +02:00
|
|
|
|
2010-03-15 21:07:31 +01:00
|
|
|
TRACE("Setting swapchain %p window from %p to %p\n", swapchain, swapchain->win_handle, window);
|
|
|
|
swapchain->win_handle = window;
|
2008-07-29 05:34:32 +02:00
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-10 21:41:54 +01:00
|
|
|
static const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl =
|
2005-06-23 13:05:24 +02:00
|
|
|
{
|
2005-07-13 16:15:54 +02:00
|
|
|
/* IUnknown */
|
2008-07-28 01:04:16 +02:00
|
|
|
IWineD3DBaseSwapChainImpl_QueryInterface,
|
|
|
|
IWineD3DBaseSwapChainImpl_AddRef,
|
|
|
|
IWineD3DBaseSwapChainImpl_Release,
|
2005-07-13 16:15:54 +02:00
|
|
|
/* IWineD3DSwapChain */
|
2008-07-28 01:04:16 +02:00
|
|
|
IWineD3DBaseSwapChainImpl_GetParent,
|
2006-12-05 00:29:14 +01:00
|
|
|
IWineD3DSwapChainImpl_Destroy,
|
2008-07-28 01:04:16 +02:00
|
|
|
IWineD3DBaseSwapChainImpl_GetDevice,
|
2005-06-23 13:05:24 +02:00
|
|
|
IWineD3DSwapChainImpl_Present,
|
2008-07-29 05:34:32 +02:00
|
|
|
IWineD3DSwapChainImpl_SetDestWindowOverride,
|
2008-07-28 01:04:16 +02:00
|
|
|
IWineD3DBaseSwapChainImpl_GetFrontBufferData,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetBackBuffer,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetRasterStatus,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetDisplayMode,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetPresentParameters,
|
|
|
|
IWineD3DBaseSwapChainImpl_SetGammaRamp,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetGammaRamp
|
2005-06-23 13:05:24 +02:00
|
|
|
};
|
2007-06-02 22:21:57 +02:00
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2009-12-10 21:41:54 +01:00
|
|
|
HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface_type,
|
2010-08-31 18:41:40 +02:00
|
|
|
IWineD3DDeviceImpl *device, WINED3DPRESENT_PARAMETERS *present_parameters, void *parent)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
const struct wined3d_adapter *adapter = device->adapter;
|
2010-08-30 20:29:49 +02:00
|
|
|
const struct wined3d_format *format;
|
2009-12-10 21:41:54 +01:00
|
|
|
BOOL displaymode_set = FALSE;
|
|
|
|
WINED3DDISPLAYMODE mode;
|
|
|
|
RECT client_rect;
|
|
|
|
HWND window;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (present_parameters->BackBufferCount > WINED3DPRESENT_BACK_BUFFER_MAX)
|
|
|
|
{
|
|
|
|
FIXME("The application requested %u back buffers, this is not supported.\n",
|
|
|
|
present_parameters->BackBufferCount);
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (present_parameters->BackBufferCount > 1)
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (surface_type)
|
|
|
|
{
|
|
|
|
case SURFACE_GDI:
|
|
|
|
swapchain->lpVtbl = &IWineGDISwapChain_Vtbl;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACE_OPENGL:
|
|
|
|
swapchain->lpVtbl = &IWineD3DSwapChain_Vtbl;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACE_UNKNOWN:
|
|
|
|
FIXME("Caller tried to create a SURFACE_UNKNOWN swapchain.\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
window = present_parameters->hDeviceWindow ? present_parameters->hDeviceWindow : device->createParms.hFocusWindow;
|
|
|
|
|
|
|
|
swapchain->device = device;
|
|
|
|
swapchain->parent = parent;
|
|
|
|
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
|
|
|
|
2011-02-01 19:39:53 +01:00
|
|
|
wined3d_get_adapter_display_mode(device->wined3d, adapter->ordinal, &mode);
|
2009-12-10 21:41:54 +01:00
|
|
|
swapchain->orig_width = mode.Width;
|
|
|
|
swapchain->orig_height = mode.Height;
|
|
|
|
swapchain->orig_fmt = mode.Format;
|
2010-08-30 20:29:49 +02:00
|
|
|
format = wined3d_get_format(&adapter->gl_info, mode.Format);
|
2009-12-10 21:41:54 +01:00
|
|
|
|
|
|
|
GetClientRect(window, &client_rect);
|
|
|
|
if (present_parameters->Windowed
|
|
|
|
&& (!present_parameters->BackBufferWidth || !present_parameters->BackBufferHeight
|
|
|
|
|| present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN))
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!present_parameters->BackBufferWidth)
|
|
|
|
{
|
|
|
|
present_parameters->BackBufferWidth = client_rect.right;
|
|
|
|
TRACE("Updating width to %u.\n", present_parameters->BackBufferWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!present_parameters->BackBufferHeight)
|
|
|
|
{
|
|
|
|
present_parameters->BackBufferHeight = client_rect.bottom;
|
|
|
|
TRACE("Updating height to %u.\n", present_parameters->BackBufferHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN)
|
|
|
|
{
|
|
|
|
present_parameters->BackBufferFormat = swapchain->orig_fmt;
|
|
|
|
TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->orig_fmt));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
swapchain->presentParms = *present_parameters;
|
|
|
|
|
|
|
|
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
|
2009-12-15 20:16:19 +01:00
|
|
|
&& present_parameters->BackBufferCount
|
2009-12-10 21:41:54 +01:00
|
|
|
&& (present_parameters->BackBufferWidth != client_rect.right
|
|
|
|
|| present_parameters->BackBufferHeight != client_rect.bottom))
|
|
|
|
{
|
|
|
|
TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u.\n",
|
|
|
|
present_parameters->BackBufferWidth,
|
|
|
|
present_parameters->BackBufferHeight,
|
|
|
|
client_rect.right, client_rect.bottom);
|
|
|
|
swapchain->render_to_fbo = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Creating front buffer.\n");
|
|
|
|
hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
|
|
|
|
swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
|
|
|
|
swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
|
2010-04-26 21:33:00 +02:00
|
|
|
swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */,
|
|
|
|
(IWineD3DSurface **)&swapchain->front_buffer);
|
2009-12-10 21:41:54 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create front buffer, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
surface_set_container(swapchain->front_buffer, WINED3D_CONTAINER_SWAPCHAIN, (IWineD3DBase *)swapchain);
|
2009-12-10 21:41:54 +01:00
|
|
|
if (surface_type == SURFACE_OPENGL)
|
|
|
|
{
|
2010-07-21 18:48:21 +02:00
|
|
|
surface_modify_location(swapchain->front_buffer, SFLAG_INDRAWABLE, TRUE);
|
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? */
|
|
|
|
|
|
|
|
if (!present_parameters->Windowed)
|
|
|
|
{
|
|
|
|
WINED3DDISPLAYMODE mode;
|
|
|
|
|
|
|
|
/* Change the display settings */
|
|
|
|
mode.Width = present_parameters->BackBufferWidth;
|
|
|
|
mode.Height = present_parameters->BackBufferHeight;
|
|
|
|
mode.Format = present_parameters->BackBufferFormat;
|
|
|
|
mode.RefreshRate = present_parameters->FullScreen_RefreshRateInHz;
|
|
|
|
|
|
|
|
hr = IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)device, 0, &mode);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to set display mode, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
displaymode_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(swapchain->context));
|
|
|
|
if (!swapchain->context)
|
|
|
|
{
|
|
|
|
ERR("Failed to create the context array.\n");
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
swapchain->num_contexts = 1;
|
|
|
|
|
|
|
|
if (surface_type == SURFACE_OPENGL)
|
|
|
|
{
|
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
|
|
|
|
};
|
|
|
|
|
2010-03-28 16:25:04 +02:00
|
|
|
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
|
|
|
|
|
|
|
|
/* 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]);
|
2010-04-30 16:44:29 +02:00
|
|
|
swapchain->context[0] = context_create(swapchain, swapchain->front_buffer, swapchain->ds_format);
|
|
|
|
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
|
|
|
|
|
|
|
if (!present_parameters->EnableAutoDepthStencil
|
2010-08-25 20:46:51 +02:00
|
|
|
|| swapchain->presentParms.AutoDepthStencilFormat != 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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
swapchain->context[0] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapchain->presentParms.BackBufferCount > 0)
|
|
|
|
{
|
2010-04-26 21:33:01 +02:00
|
|
|
swapchain->back_buffers = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
sizeof(*swapchain->back_buffers) * swapchain->presentParms.BackBufferCount);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
|
|
|
|
{
|
|
|
|
TRACE("Creating back buffer %u.\n", i);
|
|
|
|
hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
|
|
|
|
swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
|
|
|
|
swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
|
2010-04-26 21:33:01 +02:00
|
|
|
swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */,
|
|
|
|
(IWineD3DSurface **)&swapchain->back_buffers[i]);
|
2009-12-10 21:41:54 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
surface_set_container(swapchain->back_buffers[i], WINED3D_CONTAINER_SWAPCHAIN, (IWineD3DBase *)swapchain);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */
|
|
|
|
if (present_parameters->EnableAutoDepthStencil && surface_type == SURFACE_OPENGL)
|
|
|
|
{
|
|
|
|
TRACE("Creating depth/stencil buffer.\n");
|
2010-04-19 20:47:00 +02:00
|
|
|
if (!device->auto_depth_stencil)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
2010-08-30 20:29:48 +02:00
|
|
|
hr = IWineD3DDeviceParent_CreateDepthStencilSurface(device->device_parent,
|
2009-12-10 21:41:54 +01:00
|
|
|
swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
|
|
|
|
swapchain->presentParms.AutoDepthStencilFormat, swapchain->presentParms.MultiSampleType,
|
|
|
|
swapchain->presentParms.MultiSampleQuality, FALSE /* FIXME: Discard */,
|
2010-04-19 20:47:00 +02:00
|
|
|
(IWineD3DSurface **)&device->auto_depth_stencil);
|
2009-12-10 21:41:54 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create the auto depth stencil, hr %#x.\n", hr);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2010-08-16 20:00:25 +02:00
|
|
|
surface_set_container(device->auto_depth_stencil, WINED3D_CONTAINER_NONE, NULL);
|
2009-12-10 21:41:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IWineD3DSwapChain_GetGammaRamp((IWineD3DSwapChain *)swapchain, &swapchain->orig_gamma);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (displaymode_set)
|
|
|
|
{
|
|
|
|
DEVMODEW devmode;
|
|
|
|
|
|
|
|
ClipCursor(NULL);
|
|
|
|
|
|
|
|
/* Change the display settings */
|
|
|
|
memset(&devmode, 0, sizeof(devmode));
|
|
|
|
devmode.dmSize = sizeof(devmode);
|
|
|
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
|
2010-08-30 20:29:49 +02:00
|
|
|
devmode.dmBitsPerPel = format->byte_count * CHAR_BIT;
|
2009-12-10 21:41:54 +01:00
|
|
|
devmode.dmPelsWidth = swapchain->orig_width;
|
|
|
|
devmode.dmPelsHeight = swapchain->orig_height;
|
|
|
|
ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
|
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (swapchain->back_buffers)
|
2009-12-10 21:41:54 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
|
|
|
|
{
|
2010-04-26 21:33:01 +02:00
|
|
|
if (swapchain->back_buffers[i]) IWineD3DSurface_Release((IWineD3DSurface *)swapchain->back_buffers[i]);
|
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
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:00 +02:00
|
|
|
if (swapchain->front_buffer) IWineD3DSurface_Release((IWineD3DSurface *)swapchain->front_buffer);
|
2009-12-10 21:41:54 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2010-09-02 19:25:00 +02:00
|
|
|
/* Do not call while under the GL lock. */
|
2011-01-19 19:20:11 +01:00
|
|
|
static struct wined3d_context *swapchain_create_context(struct IWineD3DSwapChainImpl *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
|
|
|
|
2011-01-18 17:55:21 +01:00
|
|
|
if (!(ctx = context_create(swapchain, swapchain->front_buffer, 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-01-19 19:20:11 +01:00
|
|
|
struct wined3d_context *swapchain_get_context(struct IWineD3DSwapChainImpl *swapchain)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-08-03 08:06:51 +02:00
|
|
|
void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height)
|
2009-07-24 10:44:15 +02:00
|
|
|
{
|
2007-11-30 20:22:33 +01:00
|
|
|
/* The drawable size of an onscreen drawable is the surface size.
|
2009-07-24 10:44:15 +02:00
|
|
|
* (Actually: The window size, but the surface is created in window size) */
|
2011-03-08 19:41:07 +01:00
|
|
|
*width = context->current_rt->resource.width;
|
|
|
|
*height = context->current_rt->resource.height;
|
2007-11-30 20:22:33 +01:00
|
|
|
}
|