swapchain.c revision dce32b5ab44d19932db4c40310f864dab2b5df26
e35e9d6317da2985728e7510bea9337b9893b66evboxsync/*
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *IDirect3DSwapChain9 implementation
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *Copyright 2002-2003 Jason Edmeades
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *Copyright 2002-2003 Raphael Junqueira
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *Copyright 2005 Oliver Stieber
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *Copyright 2007-2008 Stefan Dösinger for CodeWeavers
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *This library is free software; you can redistribute it and/or
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *modify it under the terms of the GNU Lesser General Public
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *License as published by the Free Software Foundation; either
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *version 2.1 of the License, or (at your option) any later version.
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *This library is distributed in the hope that it will be useful,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *but WITHOUT ANY WARRANTY; without even the implied warranty of
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *Lesser General Public License for more details.
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *You should have received a copy of the GNU Lesser General Public
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *License along with this library; if not, write to the Free Software
f52596ee352b88100d0a2abd044c8edd3c542bd7vboxsync *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
e35e9d6317da2985728e7510bea9337b9893b66evboxsync */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync/*
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
08122b11035de1e54ce1e665dff7260fc548db72vboxsync * a choice of LGPL license versions is made available with the language indicating
08122b11035de1e54ce1e665dff7260fc548db72vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync * of the LGPL is applied is otherwise unspecified.
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#include "config.h"
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#include "wined3d_private.h"
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync/*TODO: some of the additional parameters may be required to
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync set the gamma ramp (for some weird reason microsoft have left swap gammaramp in device
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync but it operates on a swapchain, it may be a good idea to move it to IWineD3DSwapChain for IWineD3D)*/
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncWINE_DEFAULT_DEBUG_CHANNEL(d3d);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncWINE_DECLARE_DEBUG_CHANNEL(fps);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#define GLINFO_LOCATION This->device->adapter->gl_info
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifdef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncIWineD3DSwapChainImpl * swapchain_find(IWineD3DDeviceImpl *pDevice, HWND hWnd)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync{
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync UINT i;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync for (i = 0; i < pDevice->NumberOfSwapChains; ++i)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSwapChainImpl *pSwapchain = (IWineD3DSwapChainImpl*)pDevice->swapchains[i];
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (pSwapchain->win_handle == hWnd)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return pSwapchain;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return NULL;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync}
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncstatic VOID swapchain_cleanup_rt_refs(IWineD3DSwapChainImpl *pSwapchain, IWineD3DSurface *rt, int iBb)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync{
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DDeviceImpl *device = pSwapchain->device;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync struct wined3d_context *context;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync UINT i;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync for (i = 0; i < device->numContexts; ++i)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync context = device->contexts[i];
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (rt == context->current_rt)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync context->current_rt = NULL;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (device->NumberOfSwapChains)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSwapChainImpl *pDefaultSwapchain = (IWineD3DSwapChainImpl*)device->swapchains[0];
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (device->render_targets[i] == rt)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSurface *newRt;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (i)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync newRt = NULL;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync else if (iBb == -1) /* front buffer */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync newRt = pDefaultSwapchain->frontBuffer;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync newRt = pDefaultSwapchain->backBuffer ? pDefaultSwapchain->backBuffer[0] : pDefaultSwapchain->frontBuffer;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DDevice_SetRenderTarget((IWineD3DDevice*)device, i, newRt, TRUE);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync }
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync }
08122b11035de1e54ce1e665dff7260fc548db72vboxsync}
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync
2561352ae77d8f2f825526a6cbafa34b45f16972vboxsyncstatic VOID swapchain_cleanup_refs(IWineD3DSwapChainImpl *pSwapchain)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync{
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync /* first make sure the swapchain is not used by anyone */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DDeviceImpl *device = pSwapchain->device;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync struct wined3d_context *context;
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync UINT i;
b5b8f3d0d95893edd81062c1b5d0bc455cc79bc1vboxsync for (i = 0; i < device->numContexts; ++i)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync {
6eb6707c9fc46c66988caf4b4224b874985d9c2dvboxsync context = device->contexts[i];
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* pretty hacky, @todo: check if the context is acquired and re-acquire it with the new swapchain */
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if (context->currentSwapchain == pSwapchain)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync {
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync context->currentSwapchain = NULL;
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync }
08122b11035de1e54ce1e665dff7260fc548db72vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (pSwapchain->frontBuffer)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync swapchain_cleanup_rt_refs(pSwapchain, pSwapchain->frontBuffer, -1);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (pSwapchain->backBuffer)
c65e2fedaf400b449a85ae6db7b84858f2613708vboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync UINT j;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync for (j = 0; j < pSwapchain->presentParms.BackBufferCount; ++j)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync {
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync swapchain_cleanup_rt_refs(pSwapchain, pSwapchain->backBuffer[j], j);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync }
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync }
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync}
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsyncstatic VOID swapchain_invalidate(IWineD3DSwapChainImpl *pSwapchain)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync{
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync swapchain_cleanup_refs(pSwapchain);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync pSwapchain->win_handle = NULL;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync pSwapchain->hDC = NULL;
aaa80e9df329609078dea844a11f2611443b677avboxsync}
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync#endif
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
aaa80e9df329609078dea844a11f2611443b677avboxsync/*IWineD3DSwapChain parts follow: */
08e715a5fb97536a462b199124a0c6e925cfa76cvboxsyncstatic void WINAPI IWineD3DSwapChainImpl_Destroy(IWineD3DSwapChain *iface)
aaa80e9df329609078dea844a11f2611443b677avboxsync{
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync unsigned int i;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync TRACE("Destroying swapchain %p\n", iface);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync#ifdef VBOX_WITH_WDDM
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync /* first remove swapchain from a list to ensure context is properly acquired
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync * & gl resources are properly cleared on last swapchain destruction */
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync IWineD3DDevice_RemoveSwapChain((IWineD3DDevice*)This->device, (IWineD3DSwapChain*)This);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync swapchain_cleanup_refs(This);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync#endif
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync /* Release the swapchain's draw buffers. Make sure This->backBuffer[0] is
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync * the last buffer to be destroyed, FindContext() depends on that. */
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync if (This->frontBuffer)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync {
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync IWineD3DSurface_SetContainer(This->frontBuffer, 0);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync if (IWineD3DSurface_Release(This->frontBuffer))
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync {
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync WARN("(%p) Something's still holding the front buffer (%p).\n",
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync This, This->frontBuffer);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync }
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync This->frontBuffer = NULL;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync }
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync if (This->backBuffer)
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync {
aaa80e9df329609078dea844a11f2611443b677avboxsync i = This->presentParms.BackBufferCount;
aaa80e9df329609078dea844a11f2611443b677avboxsync
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync while (i--)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync IWineD3DSurface_SetContainer(This->backBuffer[i], 0);
a7f701e8c51193f7c21137cc173ea5f86e53cac2vboxsync if (IWineD3DSurface_Release(This->backBuffer[i]))
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync WARN("(%p) Something's still holding back buffer %u (%p).\n",
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync This, i, This->backBuffer[i]);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync }
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync HeapFree(GetProcessHeap(), 0, This->backBuffer);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync This->backBuffer = NULL;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync }
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync#ifndef VBOX_WINE_WITH_SINGLE_CONTEXT
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync for (i = 0; i < This->num_contexts; ++i)
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync context_destroy(This->device, This->context[i]);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifdef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (This->presentRt)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync IWineD3DSurfaceImpl *old = (IWineD3DSurfaceImpl*)This->presentRt;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync old->presentSwapchain = NULL;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync IWineD3DSurface_Release(This->presentRt);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync This->presentRt = NULL;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if(This->win_handle) {
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync VBoxExtWndDestroy(This->win_handle, This->hDC);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain_invalidate(This);
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync WARN("null win info");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#else
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DDevice_RemoveSwapChain((IWineD3DDevice*)This->device, (IWineD3DSwapChain*)This);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!This->device->NumberOfSwapChains)
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* Restore the screen resolution if we rendered in fullscreen
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync * This will restore the screen resolution to what it was before creating the swapchain. In case of d3d8 and d3d9
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync * this will be the original desktop resolution. In case of d3d7 this will be a NOP because ddraw sets the resolution
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync * before starting up Direct3D, thus orig_width and orig_height will be equal to the modes in the presentation params
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if(This->presentParms.Windowed == FALSE && This->presentParms.AutoRestoreDisplayMode) {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync WINED3DDISPLAYMODE mode;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync mode.Width = This->orig_width;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync mode.Height = This->orig_height;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync mode.RefreshRate = 0;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync mode.Format = This->orig_fmt;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)This->device, 0, &mode);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync HeapFree(GetProcessHeap(), 0, This->context);
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync#endif
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync HeapFree(GetProcessHeap(), 0, This);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync}
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync/* A GL context is provided by the caller */
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsyncstatic void swapchain_blit(IWineD3DSwapChainImpl *This, struct wined3d_context *context,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync const RECT *src_rect, const RECT *dst_rect)
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync{
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync IWineD3DDeviceImpl *device = This->device;
5cb8545771849c97101a5ee9bb57d0fdac922c44vboxsync IWineD3DSurfaceImpl *backbuffer = ((IWineD3DSurfaceImpl *) This->backBuffer[0]);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync UINT src_w = src_rect->right - src_rect->left;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync UINT src_h = src_rect->bottom - src_rect->top;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync GLenum gl_filter;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync const struct wined3d_gl_info *gl_info = context->gl_info;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync TRACE("swapchain %p, context %p, src_rect %s, dst_rect %s.\n",
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This, context, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect));
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (src_w == dst_rect->right - dst_rect->left && src_h == dst_rect->bottom - dst_rect->top)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync gl_filter = GL_NEAREST;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else
e35e9d6317da2985728e7510bea9337b9893b66evboxsync gl_filter = GL_LINEAR;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (0 && gl_info->fbo_ops.glBlitFramebuffer && is_identity_fixup(backbuffer->resource.format_desc->color_fixup))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync ENTER_GL();
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context_bind_fbo(context, GL_READ_FRAMEBUFFER, &context->src_fbo);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context_attach_surface_fbo(context, GL_READ_FRAMEBUFFER, 0, backbuffer);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context_attach_depth_stencil_fbo(context, GL_READ_FRAMEBUFFER, NULL, FALSE);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context_set_draw_buffer(context, GL_BACK);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glDisable(GL_SCISSOR_TEST);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DDeviceImpl_MarkStateDirty(This->device, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE));
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* Note that the texture is upside down */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync gl_info->fbo_ops.glBlitFramebuffer(src_rect->left, src_rect->top, src_rect->right, src_rect->bottom,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync dst_rect->left, dst_rect->bottom, dst_rect->right, dst_rect->top,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync GL_COLOR_BUFFER_BIT, gl_filter);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync checkGLcall("Swapchain present blit(EXT_framebuffer_blit)\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync LEAVE_GL();
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync struct wined3d_context *context2;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync float tex_left = src_rect->left;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync float tex_top = src_rect->top;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync float tex_right = src_rect->right;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync float tex_bottom = src_rect->bottom;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context2 = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_BLIT);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if(backbuffer->Flags & SFLAG_NORMCOORD)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync tex_left /= src_w;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync tex_right /= src_w;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync tex_top /= src_h;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync tex_bottom /= src_h;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (is_complex_fixup(backbuffer->resource.format_desc->color_fixup))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync gl_filter = GL_NEAREST;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ENTER_GL();
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync context_bind_fbo(context2, GL_DRAW_FRAMEBUFFER, NULL);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* Set up the texture. The surface is not in a IWineD3D*Texture container,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * so there are no d3d texture settings to dirtify
e35e9d6317da2985728e7510bea9337b9893b66evboxsync */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync device->blitter->set_shader((IWineD3DDevice *) device, backbuffer);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MIN_FILTER, gl_filter);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glTexParameteri(backbuffer->texture_target, GL_TEXTURE_MAG_FILTER, gl_filter);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context_set_draw_buffer(context, GL_BACK);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* Set the viewport to the destination rectandle, disable any projection
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * transformation set up by CTXUSAGE_BLIT, and draw a (-1,-1)-(1,1) quad.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * Back up viewport and matrix to avoid breaking last_was_blit
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * Note that CTXUSAGE_BLIT set up viewport and ortho to match the surface
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * size - we want the GL drawable(=window) size.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glPushAttrib(GL_VIEWPORT_BIT);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glViewport(dst_rect->left, dst_rect->top, dst_rect->right, dst_rect->bottom);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glMatrixMode(GL_PROJECTION);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glPushMatrix();
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glLoadIdentity();
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync glBegin(GL_QUADS);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* bottom left */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glTexCoord2f(tex_left, tex_bottom);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glVertex2i(-1, -1);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* top left */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glTexCoord2f(tex_left, tex_top);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glVertex2i(-1, 1);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* top right */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glTexCoord2f(tex_right, tex_top);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glVertex2i(1, 1);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* bottom right */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glTexCoord2f(tex_right, tex_bottom);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glVertex2i(1, -1);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync glEnd();
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync glPopMatrix();
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync glPopAttrib();
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync device->blitter->unset_shader((IWineD3DDevice *) device);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync checkGLcall("Swapchain present blit(manual)\n");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync LEAVE_GL();
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context_release(context2);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync}
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncstatic HRESULT WINAPI IWineD3DSwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync struct wined3d_context *context;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync RECT src_rect, dst_rect;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync BOOL render_to_fbo;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync unsigned int sync;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync int retval;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#ifdef VBOX_WITH_WDDM
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* quickly sort out invalid swapchains */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!This->hDC)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync WARN("Invalid swapchain");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return WINED3D_OK;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#endif
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync IWineD3DSwapChain_SetDestWindowOverride(iface, hDestWindowOverride);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync context = context_acquire(This->device, This->backBuffer[0], CTXUSAGE_RESOURCELOAD);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if (!context->valid)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync context_release(context);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync WARN("Invalid context, skipping present.\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return WINED3D_OK;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync /* Render the cursor onto the back buffer, using our nifty directdraw blitting code :-) */
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if (This->device->bCursorVisible && This->device->cursorTexture)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSurfaceImpl cursor;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync RECT destRect =
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This->device->xScreenSpace - This->device->xHotSpot,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This->device->yScreenSpace - This->device->yHotSpot,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This->device->xScreenSpace + This->device->cursorWidth - This->device->xHotSpot,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This->device->yScreenSpace + This->device->cursorHeight - This->device->yHotSpot,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync };
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync TRACE("Rendering the cursor. Creating fake surface at %p\n", &cursor);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync /* Build a fake surface to call the Blitting code. It is not possible to use the interface passed by
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync * the application because we are only supposed to copy the information out. Using a fake surface
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync * allows to use the Blitting engine and avoid copying the whole texture -> render target blitting code.
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync memset(&cursor, 0, sizeof(cursor));
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync cursor.lpVtbl = &IWineD3DSurface_Vtbl;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync cursor.resource.ref = 1;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync cursor.resource.device = This->device;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync cursor.resource.pool = WINED3DPOOL_SCRATCH;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync cursor.resource.format_desc = getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, context->gl_info);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync cursor.resource.resourceType = WINED3DRTYPE_SURFACE;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync cursor.texture_name = This->device->cursorTexture;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync cursor.texture_target = GL_TEXTURE_2D;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync cursor.texture_level = 0;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync cursor.currentDesc.Width = This->device->cursorWidth;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync cursor.currentDesc.Height = This->device->cursorHeight;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync /* The cursor must have pow2 sizes */
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync cursor.pow2Width = cursor.currentDesc.Width;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync cursor.pow2Height = cursor.currentDesc.Height;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync /* The surface is in the texture */
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync cursor.Flags |= SFLAG_INTEXTURE;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync /* DDBLT_KEYSRC will cause BltOverride to enable the alpha test with GL_NOTEQUAL, 0.0,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * which is exactly what we want :-)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync */
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if (This->presentParms.Windowed) {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#ifdef VBOX_WITH_WDDM
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync /* @todo: can we actualy be here? */
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync MapWindowPoints(NULL, This->win_handle, (LPPOINT)&destRect, 2);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync IWineD3DSurface_Blt(This->backBuffer[0], &destRect, (IWineD3DSurface *)&cursor,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync NULL, WINEDDBLT_KEYSRC, NULL, WINED3DTEXF_POINT);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (This->device->logo_surface)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync /* Blit the logo into the upper left corner of the drawable. */
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync IWineD3DSurface_BltFast(This->backBuffer[0], 0, 0, This->device->logo_surface, NULL, WINEDDBLTFAST_SRCCOLORKEY);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#ifdef VBOX_WITH_WDDM
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync TRACE("Presenting HDC %p.\n", context->currentSwapchain->hDC);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync TRACE("Presenting HDC %p.\n", context->hdc);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync render_to_fbo = This->render_to_fbo;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (pSourceRect)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync src_rect = *pSourceRect;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!render_to_fbo && (src_rect.left || src_rect.top
e35e9d6317da2985728e7510bea9337b9893b66evboxsync || src_rect.right != This->presentParms.BackBufferWidth
e35e9d6317da2985728e7510bea9337b9893b66evboxsync || src_rect.bottom != This->presentParms.BackBufferHeight))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync render_to_fbo = TRUE;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync src_rect.left = 0;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync src_rect.top = 0;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync src_rect.right = This->presentParms.BackBufferWidth;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync src_rect.bottom = This->presentParms.BackBufferHeight;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (pDestRect) dst_rect = *pDestRect;
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync#ifndef VBOX_WITH_WDDM
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else
e35e9d6317da2985728e7510bea9337b9893b66evboxsync GetClientRect(This->win_handle, &dst_rect);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!render_to_fbo && (dst_rect.left || dst_rect.top
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync || dst_rect.right != This->presentParms.BackBufferWidth
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync || dst_rect.bottom != This->presentParms.BackBufferHeight))
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync {
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync render_to_fbo = TRUE;
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync }
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync#else
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync else
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync {
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync dst_rect.left = 0;
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync dst_rect.top = 0;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync dst_rect.right = This->presentParms.BackBufferWidth;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync dst_rect.bottom = This->presentParms.BackBufferHeight;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync /* Rendering to a window of different size, presenting partial rectangles,
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * or rendering to a different window needs help from FBO_blit or a textured
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * draw. Render the swapchain to a FBO in the future.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync *
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * Note that FBO_blit from the backbuffer to the frontbuffer cannot solve
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * all these issues - this fails if the window is smaller than the backbuffer.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!This->render_to_fbo && render_to_fbo && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSurface_LoadLocation(This->backBuffer[0], SFLAG_INTEXTURE, NULL);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSurface_ModifyLocation(This->backBuffer[0], SFLAG_INDRAWABLE, FALSE);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync This->render_to_fbo = TRUE;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* Force the context manager to update the render target configuration next draw. */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync context->current_rt = NULL;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync if(This->render_to_fbo)
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync {
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync /* This codepath should only be hit with the COPY swapeffect. Otherwise a backbuffer-
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * window size mismatch is impossible(fullscreen) and src and dst rectangles are
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * not allowed(they need the COPY swapeffect)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync *
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * The DISCARD swap effect is ok as well since any backbuffer content is allowed after
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * the swap
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync */
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP )
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync FIXME("Render-to-fbo with WINED3DSWAPEFFECT_FLIP\n");
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync }
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync swapchain_blit(This, context, &src_rect, &dst_rect);
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync }
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync#ifdef VBOX_WITH_WDDM
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync if (This->device->numContexts > 1) wglFinish();
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync#else
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync if (This->num_contexts > 1) wglFinish();
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync#endif
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync#if defined(VBOX_WITH_WDDM) && defined(DEBUG)
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync {
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync HWND wnd = WindowFromDC(context->currentSwapchain->hDC);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync Assert(wnd == context->currentSwapchain->win_handle);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifdef VBOX_WITH_WDDM
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync /* We're directly using wglMakeCurrent calls skipping GDI layer, which causes GDI SwapBuffers to fail trying to
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * call glFinish, which doesn't have any context set. So we use wglSwapLayerBuffers directly as well.
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync */
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync pwglSwapLayerBuffers(context->currentSwapchain->hDC, WGL_SWAP_MAIN_PLANE);
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync#else
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync# ifdef VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync pwglSwapLayerBuffers(context->hdc, WGL_SWAP_MAIN_PLANE);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync# else
3eef14636dd78f6e25610b89aec40879e657caf4vboxsync SwapBuffers(context->hdc); /* TODO: cycle through the swapchain buffers */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync# endif
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#endif
da570ef57fe454ae2d9d5d88a7bfea214723dbb1vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync TRACE("SwapBuffers called, Starting new frame\n");
1d96c25e994a2160c1697208bb398d79ca117c4avboxsync /* FPS support */
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if (TRACE_ON(fps))
08122b11035de1e54ce1e665dff7260fc548db72vboxsync {
1d96c25e994a2160c1697208bb398d79ca117c4avboxsync DWORD time = GetTickCount();
08122b11035de1e54ce1e665dff7260fc548db72vboxsync This->frames++;
2ea0ec406117609d51bd5ac51cbb3d4f0de9a16dvboxsync /* every 1.5 seconds */
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if (time - This->prev_time > 1500) {
08122b11035de1e54ce1e665dff7260fc548db72vboxsync TRACE_(fps)("%p @ approx %.2ffps\n", This, 1000.0*This->frames/(time - This->prev_time));
08122b11035de1e54ce1e665dff7260fc548db72vboxsync This->prev_time = time;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync This->frames = 0;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync#if defined(FRAME_DEBUGGING)
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync{
1d27f9d208503988168cd9a8a902a0f48cf52a12vboxsync if (GetFileAttributesA("C:\\D3DTRACE") != INVALID_FILE_ATTRIBUTES) {
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync if (!isOn) {
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync isOn = TRUE;
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync FIXME("Enabling D3D Trace\n");
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 1);
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync#if defined(SHOW_FRAME_MAKEUP)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync FIXME("Singe Frame snapshots Starting\n");
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync isDumpingFrames = TRUE;
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync ENTER_GL();
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync glClear(GL_COLOR_BUFFER_BIT);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync LEAVE_GL();
989c8375a95357db2bd39e0897fdcb218e749b30vboxsync#endif
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#if defined(SINGLE_FRAME_DEBUGGING)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync } else {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#if defined(SHOW_FRAME_MAKEUP)
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsync FIXME("Singe Frame snapshots Finishing\n");
b844a5645b69a09c4d6dacb9cfe96bb138cb21d4vboxsync isDumpingFrames = FALSE;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync FIXME("Singe Frame trace complete\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync DeleteFileA("C:\\D3DTRACE");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 0);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync } else {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (isOn) {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync isOn = FALSE;
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync#if defined(SHOW_FRAME_MAKEUP)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync FIXME("Single Frame snapshots Finishing\n");
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync isDumpingFrames = FALSE;
dafcc1aee6fa9a280e6c6d7630132e5a778f3a6fvboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync FIXME("Disabling D3D Trace\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE, __wine_dbch_d3d, 0);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync}
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync#endif
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync /* This is disabled, but the code left in for debug purposes.
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync *
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync * Since we're allowed to modify the new back buffer on a D3DSWAPEFFECT_DISCARD flip,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * we can clear it with some ugly color to make bad drawing visible and ease debugging.
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync * The Debug runtime does the same on Windows. However, a few games do not redraw the
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync * screen properly, like Max Payne 2, which leaves a few pixels undefined.
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync *
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * Tests show that the content of the back buffer after a discard flip is indeed not
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync * reliable, so no game can depend on the exact content. However, it resembles the
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * old contents in some way, for example by showing fragments at other locations. In
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync * general, the color theme is still intact. So Max payne, which draws rather dark scenes
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync * gets a dark background image. If we clear it with a bright ugly color, the game's
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * bug shows up much more than it does on Windows, and the players see single pixels
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * with wrong colors.
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * (The Max Payne bug has been confirmed on Windows with the debug runtime)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync */
e9802cd9ee289e494f01f2c37e714911d120cd30vboxsync if (FALSE && This->presentParms.SwapEffect == WINED3DSWAPEFFECT_DISCARD) {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync TRACE("Clearing the color buffer with cyan color\n");
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DDevice_Clear((IWineD3DDevice *)This->device, 0, NULL,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync WINED3DCLEAR_TARGET, 0xff00ffff, 1.0f, 0);
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync }
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if(!This->render_to_fbo &&
a23d9b6011c292ab4d858fc7d83a2216843cd54evboxsync ( ((IWineD3DSurfaceImpl *) This->frontBuffer)->Flags & SFLAG_INSYSMEM ||
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync ((IWineD3DSurfaceImpl *) This->backBuffer[0])->Flags & SFLAG_INSYSMEM ) ) {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* Both memory copies of the surfaces are ok, flip them around too instead of dirtifying
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync * Doesn't work with render_to_fbo because we're not flipping
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync */
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync IWineD3DSurfaceImpl *front = (IWineD3DSurfaceImpl *) This->frontBuffer;
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync IWineD3DSurfaceImpl *back = (IWineD3DSurfaceImpl *) This->backBuffer[0];
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if(front->resource.size == back->resource.size) {
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync DWORD fbflags;
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync flip_surface(front, back);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync /* Tell the front buffer surface that is has been modified. However,
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync * the other locations were preserved during that, so keep the flags.
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync * This serves to update the emulated overlay, if any
e35e9d6317da2985728e7510bea9337b9893b66evboxsync */
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync fbflags = front->Flags;
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync IWineD3DSurface_ModifyLocation(This->frontBuffer, SFLAG_INDRAWABLE, TRUE);
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync front->Flags = fbflags;
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync } else {
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync IWineD3DSurface_ModifyLocation((IWineD3DSurface *) front, SFLAG_INDRAWABLE, TRUE);
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync IWineD3DSurface_ModifyLocation((IWineD3DSurface *) back, SFLAG_INDRAWABLE, TRUE);
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync }
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync } else {
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync IWineD3DSurface_ModifyLocation(This->frontBuffer, SFLAG_INDRAWABLE, TRUE);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* If the swapeffect is DISCARD, the back buffer is undefined. That means the SYSMEM
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync * and INTEXTURE copies can keep their old content if they have any defined content.
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync * If the swapeffect is COPY, the content remains the same. If it is FLIP however,
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync * the texture / sysmem copy needs to be reloaded from the drawable
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync */
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync if(This->presentParms.SwapEffect == WINED3DSWAPEFFECT_FLIP) {
ee231a249824f0a96643fb8b705f5b6cf3617b46vboxsync IWineD3DSurface_ModifyLocation(This->backBuffer[0], SFLAG_INDRAWABLE, TRUE);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync if (This->device->stencilBufferTarget)
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync {
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync if (This->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync || ((IWineD3DSurfaceImpl *)This->device->stencilBufferTarget)->Flags & SFLAG_DISCARD)
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync surface_modify_ds_location(This->device->stencilBufferTarget, SFLAG_DS_DISCARDED);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync }
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync if (This->presentParms.PresentationInterval != WINED3DPRESENT_INTERVAL_IMMEDIATE
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync && context->gl_info->supported[SGI_VIDEO_SYNC])
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync retval = GL_EXTCALL(glXGetVideoSyncSGI(&sync));
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if(retval != 0) {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ERR("glXGetVideoSyncSGI failed(retval = %d\n", retval);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync switch(This->presentParms.PresentationInterval) {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync case WINED3DPRESENT_INTERVAL_DEFAULT:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync case WINED3DPRESENT_INTERVAL_ONE:
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if(sync <= This->vSyncCounter) {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync retval = GL_EXTCALL(glXWaitVideoSyncSGI(1, 0, &This->vSyncCounter));
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync } else {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync This->vSyncCounter = sync;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync break;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync case WINED3DPRESENT_INTERVAL_TWO:
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if(sync <= This->vSyncCounter + 1) {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync retval = GL_EXTCALL(glXWaitVideoSyncSGI(2, This->vSyncCounter & 0x1, &This->vSyncCounter));
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync } else {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync This->vSyncCounter = sync;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync break;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync case WINED3DPRESENT_INTERVAL_THREE:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if(sync <= This->vSyncCounter + 2) {
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync retval = GL_EXTCALL(glXWaitVideoSyncSGI(3, This->vSyncCounter % 0x3, &This->vSyncCounter));
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync } else {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This->vSyncCounter = sync;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync break;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync case WINED3DPRESENT_INTERVAL_FOUR:
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if(sync <= This->vSyncCounter + 3) {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync retval = GL_EXTCALL(glXWaitVideoSyncSGI(4, This->vSyncCounter & 0x3, &This->vSyncCounter));
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync } else {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync This->vSyncCounter = sync;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync break;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync default:
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync FIXME("Unknown presentation interval %08x\n", This->presentParms.PresentationInterval);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync context_release(context);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync TRACE("returning\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return WINED3D_OK;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync}
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
50c3ee6cc6a9f816790595907558b355769f9c44vboxsyncstatic HRESULT WINAPI IWineD3DSwapChainImpl_SetDestWindowOverride(IWineD3DSwapChain *iface, HWND window)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync{
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifndef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)iface;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if (!window) window = swapchain->device_window;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (window == swapchain->win_handle) return WINED3D_OK;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync TRACE("Setting swapchain %p window from %p to %p\n", swapchain, swapchain->win_handle, window);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain->win_handle = window;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return WINED3D_OK;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync}
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifdef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncstatic HRESULT IWineD3DBaseSwapChainImpl_PresentRtPerform(IWineD3DSwapChainImpl* This)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync{
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DSurface *pBb = This->backBuffer[0];
e35e9d6317da2985728e7510bea9337b9893b66evboxsync HRESULT hr = IWineD3DSurface_Blt(pBb, NULL, This->presentRt, NULL, 0, NULL, 0);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (FAILED(hr))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ERR("IWineD3DSurface_Blt failed with hr(%d)", hr);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync return hr;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync hr = IWineD3DSwapChainImpl_Present((IWineD3DSwapChain*)This, NULL, NULL, NULL, NULL, 0);
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if (FAILED(hr))
08122b11035de1e54ce1e665dff7260fc548db72vboxsync {
08122b11035de1e54ce1e665dff7260fc548db72vboxsync ERR("IWineD3DSurface_Blt failed with hr(%d)", hr);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return hr;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return S_OK;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync}
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsyncHRESULT WINAPI IWineD3DBaseSwapChainImpl_Flush(IWineD3DSwapChain* This)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync{
08122b11035de1e54ce1e665dff7260fc548db72vboxsync /* @todo: if we're in PresentRt mode, check whether the current present rt is updated
08122b11035de1e54ce1e665dff7260fc548db72vboxsync * and do present to frontbuffer if needed */
08122b11035de1e54ce1e665dff7260fc548db72vboxsync return S_OK;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync}
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsyncHRESULT WINAPI IWineD3DBaseSwapChainImpl_PresentRt(IWineD3DSwapChain* iface, IWineD3DSurface* surf)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync{
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl*)iface;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)surf;
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync if (This->presentRt != surf)
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync {
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync if (surf)
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync {
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync IWineD3DSurface_AddRef(surf);
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync if (surface->presentSwapchain)
5c57f3ae389a4fd2d1614c2a02a52bc7d56ee7b5vboxsync {
2fd917a77df587742609eaa229c7cf4922458ae8vboxsync ERR("not expected");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Assert(surface->presentSwapchain != iface);
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync IWineD3DBaseSwapChainImpl_PresentRt(surface->presentSwapchain, NULL);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync surface->presentSwapchain = iface;
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync }
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync if (This->presentRt)
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync {
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync IWineD3DSurfaceImpl *old = (IWineD3DSurfaceImpl*)This->presentRt;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Assert(old->presentSwapchain == iface);
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync old->presentSwapchain = NULL;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSurface_Release(This->presentRt);
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync }
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync This->presentRt = surf;
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync }
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync if (surf)
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync return IWineD3DBaseSwapChainImpl_PresentRtPerform(This);
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync return S_OK;
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync}
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync#endif
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsyncstatic const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl =
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync{
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync /* IUnknown */
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync IWineD3DBaseSwapChainImpl_QueryInterface,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DBaseSwapChainImpl_AddRef,
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync IWineD3DBaseSwapChainImpl_Release,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* IWineD3DSwapChain */
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync IWineD3DBaseSwapChainImpl_GetParent,
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync IWineD3DSwapChainImpl_Destroy,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DBaseSwapChainImpl_GetDevice,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync IWineD3DSwapChainImpl_Present,
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync IWineD3DSwapChainImpl_SetDestWindowOverride,
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync IWineD3DBaseSwapChainImpl_GetFrontBufferData,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DBaseSwapChainImpl_GetBackBuffer,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DBaseSwapChainImpl_GetRasterStatus,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DBaseSwapChainImpl_GetDisplayMode,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync IWineD3DBaseSwapChainImpl_GetPresentParameters,
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync IWineD3DBaseSwapChainImpl_SetGammaRamp,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync IWineD3DBaseSwapChainImpl_GetGammaRamp,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#ifdef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DBaseSwapChainImpl_Flush,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync IWineD3DBaseSwapChainImpl_PresentRt,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync};
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncstatic LONG fullscreen_style(LONG style)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync{
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync /* Make sure the window is managed, otherwise we won't get keyboard input. */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync style |= WS_POPUP | WS_SYSMENU;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync style &= ~(WS_CAPTION | WS_THICKFRAME);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync return style;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync}
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsyncstatic LONG fullscreen_exstyle(LONG exstyle)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync{
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* Filter out window decorations. */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync exstyle &= ~(WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return exstyle;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync}
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncvoid swapchain_setup_fullscreen_window(IWineD3DSwapChainImpl *swapchain, UINT w, UINT h)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync{
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifdef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync ERR("not supported");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DDeviceImpl *device = swapchain->device;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync HWND window = swapchain->device_window;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync BOOL filter_messages;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync LONG style, exstyle;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync TRACE("Setting up window %p for fullscreen mode.\n", window);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (device->style || device->exStyle)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync ERR("Changing the window style for window %p, but another style (%08x, %08x) is already stored.\n",
e35e9d6317da2985728e7510bea9337b9893b66evboxsync window, device->style, device->exStyle);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync device->style = GetWindowLongW(window, GWL_STYLE);
08122b11035de1e54ce1e665dff7260fc548db72vboxsync device->exStyle = GetWindowLongW(window, GWL_EXSTYLE);
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync style = fullscreen_style(device->style);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync exstyle = fullscreen_exstyle(device->exStyle);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync TRACE("Old style was %08x, %08x, setting to %08x, %08x.\n",
e35e9d6317da2985728e7510bea9337b9893b66evboxsync device->style, device->exStyle, style, exstyle);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync filter_messages = device->filter_messages;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync device->filter_messages = TRUE;
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync SetWindowLongW(window, GWL_STYLE, style);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync SetWindowLongW(window, GWL_EXSTYLE, exstyle);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync SetWindowPos(window, HWND_TOP, 0, 0, w, h, SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync device->filter_messages = filter_messages;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#endif
e35e9d6317da2985728e7510bea9337b9893b66evboxsync}
5857f4e58ce2ef50d7f0c450fe4897026f9a9c3dvboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncvoid swapchain_restore_fullscreen_window(IWineD3DSwapChainImpl *swapchain)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync{
08122b11035de1e54ce1e665dff7260fc548db72vboxsync#ifdef VBOX_WITH_WDDM
08122b11035de1e54ce1e665dff7260fc548db72vboxsync ERR("not supported");
355edde34018a687b4a4d17054c378b780e3d8abvboxsync#else
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync IWineD3DDeviceImpl *device = swapchain->device;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync HWND window = swapchain->device_window;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync BOOL filter_messages;
36a0cf44771c76b56b4a6489136e3adf0343df0bvboxsync LONG style, exstyle;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!device->style && !device->exStyle) return;
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync TRACE("Restoring window style of window %p to %08x, %08x.\n",
e35e9d6317da2985728e7510bea9337b9893b66evboxsync window, device->style, device->exStyle);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
5c41f17e15c70a02e57fd39155f6394ebd9add66vboxsync style = GetWindowLongW(window, GWL_STYLE);
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync exstyle = GetWindowLongW(window, GWL_EXSTYLE);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync filter_messages = device->filter_messages;
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync device->filter_messages = TRUE;
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync /* Only restore the style if the application didn't modify it during the
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync * fullscreen phase. Some applications change it before calling Reset()
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync * when switching between windowed and fullscreen modes (HL2), some
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync * depend on the original style (Eve Online). */
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync if (style == fullscreen_style(device->style) && exstyle == fullscreen_exstyle(device->exStyle))
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync SetWindowLongW(window, GWL_STYLE, device->style);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync SetWindowLongW(window, GWL_EXSTYLE, device->exStyle);
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync SetWindowPos(window, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync device->filter_messages = filter_messages;
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* Delete the old values. */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync device->style = 0;
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync device->exStyle = 0;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
ced49ddf2480e97120d7bb28cd774ab609047875vboxsync}
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsyncHRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface_type,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DDeviceImpl *device, WINED3DPRESENT_PARAMETERS *present_parameters, IUnknown *parent)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync{
e35e9d6317da2985728e7510bea9337b9893b66evboxsync const struct wined3d_adapter *adapter = device->adapter;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync const struct wined3d_format_desc *format_desc;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync BOOL displaymode_set = FALSE;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync WINED3DDISPLAYMODE mode;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync RECT client_rect;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync HWND window = NULL;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#ifdef VBOX_WITH_WDDM
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DSwapChainImpl *overridenSwapchain = NULL;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync HDC hDC = NULL;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#endif
e35e9d6317da2985728e7510bea9337b9893b66evboxsync HRESULT hr;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync UINT i;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (present_parameters->BackBufferCount > WINED3DPRESENT_BACK_BUFFER_MAX)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ERR("The application requested %u back buffers, this is not supported.\n",
e35e9d6317da2985728e7510bea9337b9893b66evboxsync present_parameters->BackBufferCount);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return WINED3DERR_INVALIDCALL;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (present_parameters->BackBufferCount > 1)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync FIXME("The application requested more than one back buffer, this is not properly supported.\n"
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync "Please configure the application to use double buffering (1 back buffer) if possible.\n");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync switch (surface_type)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync case SURFACE_GDI:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->lpVtbl = &IWineGDISwapChain_Vtbl;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync break;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync case SURFACE_OPENGL:
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain->lpVtbl = &IWineD3DSwapChain_Vtbl;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync break;
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync case SURFACE_UNKNOWN:
e35e9d6317da2985728e7510bea9337b9893b66evboxsync FIXME("Caller tried to create a SURFACE_UNKNOWN swapchain.\n");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return WINED3DERR_INVALIDCALL;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#ifdef VBOX_WITH_WDDM
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (present_parameters->hDeviceWindow)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync overridenSwapchain = swapchain_find(device, present_parameters->hDeviceWindow);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!overridenSwapchain)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ERR("invalid window handle supplied");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync return E_FAIL;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync window = overridenSwapchain->win_handle;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hDC = overridenSwapchain->hDC;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync else
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync hr = VBoxExtWndCreate(present_parameters->BackBufferWidth, present_parameters->BackBufferHeight, &window, &hDC);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (FAILED(hr))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ERR("VBoxExtWndCreate failed, hr 0x%x", hr);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return hr;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync Assert(window);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync Assert(hDC);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync present_parameters->hDeviceWindow = window;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync window = present_parameters->hDeviceWindow ? present_parameters->hDeviceWindow : device->createParms.hFocusWindow;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->device = device;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync swapchain->parent = parent;
8b2f1e9e24bf9cb4340412463a0e75c4e0b035a6vboxsync swapchain->ref = 1;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->win_handle = window;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifndef VBOX_WITH_WDDM
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->device_window = window;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync Assert(window);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->hDC = hDC;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->presentRt = NULL;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (!present_parameters->Windowed && window)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain_setup_fullscreen_window(swapchain, present_parameters->BackBufferWidth,
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync present_parameters->BackBufferHeight);
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3D_GetAdapterDisplayMode(device->wined3d, adapter->ordinal, &mode);
0c657f93ac727a3a1644497331d86fbcbc3722aavboxsync swapchain->orig_width = mode.Width;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain->orig_height = mode.Height;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain->orig_fmt = mode.Format;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync format_desc = getFormatDescEntry(mode.Format, &adapter->gl_info);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync#ifndef VBOX_WITH_WDDM
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync GetClientRect(window, &client_rect);
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync#else
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync client_rect.left = 0;
b24a4c8472377f462bad08867b6203fe8bbe9663vboxsync client_rect.top = 0;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync client_rect.right = present_parameters->BackBufferWidth;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync client_rect.bottom = present_parameters->BackBufferHeight;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#endif
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (present_parameters->Windowed
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync && (!present_parameters->BackBufferWidth || !present_parameters->BackBufferHeight
e35e9d6317da2985728e7510bea9337b9893b66evboxsync || present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
08122b11035de1e54ce1e665dff7260fc548db72vboxsync if (!present_parameters->BackBufferWidth)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync present_parameters->BackBufferWidth = client_rect.right;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync TRACE("Updating width to %u.\n", present_parameters->BackBufferWidth);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (!present_parameters->BackBufferHeight)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync present_parameters->BackBufferHeight = client_rect.bottom;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync TRACE("Updating height to %u.\n", present_parameters->BackBufferHeight);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
08122b11035de1e54ce1e665dff7260fc548db72vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (present_parameters->BackBufferFormat == WINED3DFMT_UNKNOWN)
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync {
08122b11035de1e54ce1e665dff7260fc548db72vboxsync present_parameters->BackBufferFormat = swapchain->orig_fmt;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync TRACE("Updating format to %s.\n", debug_d3dformat(swapchain->orig_fmt));
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync swapchain->presentParms = *present_parameters;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
e35e9d6317da2985728e7510bea9337b9893b66evboxsync && present_parameters->BackBufferCount
e35e9d6317da2985728e7510bea9337b9893b66evboxsync && (present_parameters->BackBufferWidth != client_rect.right
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync || present_parameters->BackBufferHeight != client_rect.bottom))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync TRACE("Rendering to FBO. Backbuffer %ux%u, window %ux%u.\n",
e35e9d6317da2985728e7510bea9337b9893b66evboxsync present_parameters->BackBufferWidth,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync present_parameters->BackBufferHeight,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync client_rect.right, client_rect.bottom);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync swapchain->render_to_fbo = TRUE;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync TRACE("Creating front buffer.\n");
e35e9d6317da2985728e7510bea9337b9893b66evboxsync hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, &swapchain->frontBuffer);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (FAILED(hr))
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync WARN("Failed to create front buffer, hr %#x.\n", hr);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync goto err;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DSurface_SetContainer(swapchain->frontBuffer, (IWineD3DBase *)swapchain);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync ((IWineD3DSurfaceImpl *)swapchain->frontBuffer)->Flags |= SFLAG_SWAPCHAIN;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (surface_type == SURFACE_OPENGL)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync IWineD3DSurface_ModifyLocation(swapchain->frontBuffer, SFLAG_INDRAWABLE, TRUE);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync /* MSDN says we're only allowed a single fullscreen swapchain per device,
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * so we should really check to see if there is a fullscreen swapchain
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * already. Does a single head count as full screen? */
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!present_parameters->Windowed)
08122b11035de1e54ce1e665dff7260fc548db72vboxsync {
08122b11035de1e54ce1e665dff7260fc548db72vboxsync WINED3DDISPLAYMODE mode;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync /* Change the display settings */
c792fe5d6a56055c4d060db36316c4dac5311c7evboxsync mode.Width = present_parameters->BackBufferWidth;
e8061cc98e3d41ea42f0f835db3501d58c26e7fbvboxsync mode.Height = present_parameters->BackBufferHeight;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync mode.Format = present_parameters->BackBufferFormat;
d6bdf8a836b8e7d95eec19c254cd39161731d48fvboxsync mode.RefreshRate = present_parameters->FullScreen_RefreshRateInHz;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync hr = IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)device, 0, &mode);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (FAILED(hr))
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync WARN("Failed to set display mode, hr %#x.\n", hr);
e35e9d6317da2985728e7510bea9337b9893b66evboxsync goto err;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
e35e9d6317da2985728e7510bea9337b9893b66evboxsync displaymode_set = TRUE;
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#ifndef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(swapchain->context));
e35e9d6317da2985728e7510bea9337b9893b66evboxsync if (!swapchain->context)
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync ERR("Failed to create the context array.\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync hr = E_OUTOFMEMORY;
c2e62d39261f9f69ab4e14b2bbd986bf1b1faaf9vboxsync goto err;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync }
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync swapchain->num_contexts = 1;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#endif
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
8952a4a0ea65bcb9926a1da734c1828baff52f54vboxsync if (surface_type == SURFACE_OPENGL)
e35e9d6317da2985728e7510bea9337b9893b66evboxsync {
e35e9d6317da2985728e7510bea9337b9893b66evboxsync#ifdef VBOX_WITH_WDDM
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync struct wined3d_context * swapchainContext;
619da14dbf1f40ada039a6ebceedec8a6abe7696vboxsync#endif
e35e9d6317da2985728e7510bea9337b9893b66evboxsync const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
e35e9d6317da2985728e7510bea9337b9893b66evboxsync
e35e9d6317da2985728e7510bea9337b9893b66evboxsync /* In WGL both color, depth and stencil are features of a pixel format. In case of D3D they are separate.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * You are able to add a depth + stencil surface at a later stage when you need it.
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * In order to support this properly in WineD3D we need the ability to recreate the opengl context and
e35e9d6317da2985728e7510bea9337b9893b66evboxsync * drawable when this is required. This is very tricky as we need to reapply ALL opengl states for the new
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync * context, need torecreate shaders, textures and other resources.
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync *
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync * The context manager already takes care of the state problem and for the other tasks code from Reset
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync * can be used. These changes are way to risky during the 1.0 code freeze which is taking place right now.
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync * Likely a lot of other new bugs will be exposed. For that reason request a depth stencil surface all the
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync * issue needs to be fixed. */
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync if (!present_parameters->EnableAutoDepthStencil
15eedc898539502083b8ce6db7c3d53d805fb9advboxsync || swapchain->presentParms.AutoDepthStencilFormat != WINED3DFMT_D24_UNORM_S8_UINT)
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync {
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync FIXME("Add OpenGL context recreation support to context_validate_onscreen_formats\n");
20606357beeba9ef9025b662f5e3d178dd37d559vboxsync }
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync swapchain->ds_format = getFormatDescEntry(WINED3DFMT_D24_UNORM_S8_UINT, gl_info);
ebb33f3aef3b410579a2865109426b798b9d4a9dvboxsync
8532fcd8b260a1648f09ab3df65e5353aa148825vboxsync#ifdef VBOX_WITH_WDDM
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchainContext = context_find_create(device, swapchain, (IWineD3DSurfaceImpl *)swapchain->frontBuffer,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->ds_format);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if (!swapchainContext)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain->context[0] = context_create(swapchain, (IWineD3DSurfaceImpl *)swapchain->frontBuffer,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->ds_format);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if (!swapchain->context[0])
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync#endif
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync WARN("Failed to create context.\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync hr = WINED3DERR_NOTAVAILABLE;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync goto err;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifdef VBOX_WITH_WDDM
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync context_release(swapchainContext);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync#else
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync context_release(swapchain->context[0]);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync#endif
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync else
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#ifndef VBOX_WITH_WDDM
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->context[0] = NULL;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if (swapchain->presentParms.BackBufferCount > 0)
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->backBuffer = HeapAlloc(GetProcessHeap(), 0,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync sizeof(*swapchain->backBuffer) * swapchain->presentParms.BackBufferCount);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (!swapchain->backBuffer)
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync ERR("Failed to allocate backbuffer array memory.\n");
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync hr = E_OUTOFMEMORY;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync goto err;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync }
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync TRACE("Creating back buffer %u.\n", i);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync hr = IWineD3DDeviceParent_CreateRenderTarget(device->device_parent, parent,
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync swapchain->presentParms.BackBufferFormat, swapchain->presentParms.MultiSampleType,
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync swapchain->presentParms.MultiSampleQuality, TRUE /* Lockable */, &swapchain->backBuffer[i]);
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if (FAILED(hr))
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync {
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync WARN("Failed to create back buffer %u, hr %#x.\n", i, hr);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync goto err;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync IWineD3DSurface_SetContainer(swapchain->backBuffer[i], (IWineD3DBase *)swapchain);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync ((IWineD3DSurfaceImpl *)swapchain->backBuffer[i])->Flags |= SFLAG_SWAPCHAIN;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync /* Swapchains share the depth/stencil buffer, so only create a single depthstencil surface. */
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync if (present_parameters->EnableAutoDepthStencil && surface_type == SURFACE_OPENGL)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync TRACE("Creating depth/stencil buffer.\n");
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if (!device->auto_depth_stencil_buffer)
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync hr = IWineD3DDeviceParent_CreateDepthStencilSurface(device->device_parent, parent,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->presentParms.BackBufferWidth, swapchain->presentParms.BackBufferHeight,
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync swapchain->presentParms.AutoDepthStencilFormat, swapchain->presentParms.MultiSampleType,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain->presentParms.MultiSampleQuality, FALSE /* FIXME: Discard */,
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync &device->auto_depth_stencil_buffer);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if (FAILED(hr))
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync {
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync WARN("Failed to create the auto depth stencil, hr %#x.\n", hr);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync goto err;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync IWineD3DSurface_SetContainer(device->auto_depth_stencil_buffer, NULL);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync IWineD3DSwapChain_GetGammaRamp((IWineD3DSwapChain *)swapchain, &swapchain->orig_gamma);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync#ifdef VBOX_WITH_WDDM
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if (overridenSwapchain)
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync {
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync swapchain_invalidate(overridenSwapchain);
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync#endif
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync return WINED3D_OK;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsyncerr:
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync if (displaymode_set)
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync {
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync DEVMODEW devmode;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync ClipCursor(NULL);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync /* Change the display settings */
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync memset(&devmode, 0, sizeof(devmode));
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync devmode.dmSize = sizeof(devmode);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
a253309ecf51232be71a5c0f7b888e03f51906a3vboxsync devmode.dmBitsPerPel = format_desc->byte_count * 8;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync devmode.dmPelsWidth = swapchain->orig_width;
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync devmode.dmPelsHeight = swapchain->orig_height;
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync }
15fe3cf8212d4ca73ea0a4fe547892bcddef6e16vboxsync
50c3ee6cc6a9f816790595907558b355769f9c44vboxsync if (swapchain->backBuffer)
{
for (i = 0; i < swapchain->presentParms.BackBufferCount; ++i)
{
if (swapchain->backBuffer[i]) IWineD3DSurface_Release(swapchain->backBuffer[i]);
}
HeapFree(GetProcessHeap(), 0, swapchain->backBuffer);
}
#ifdef VBOX_WITH_WDDM
if (!device->NumberOfSwapChains)
{
while (device->numContexts)
{
context_destroy(device, device->contexts[0]);
}
}
#else
if (swapchain->context)
{
if (swapchain->context[0])
{
context_release(swapchain->context[0]);
context_destroy(device, swapchain->context[0]);
swapchain->num_contexts = 0;
}
HeapFree(GetProcessHeap(), 0, swapchain->context);
}
#endif
if (swapchain->frontBuffer) IWineD3DSurface_Release(swapchain->frontBuffer);
#ifdef VBOX_WITH_WDDM
if (!overridenSwapchain && swapchain->win_handle)
{
VBoxExtWndDestroy(swapchain->win_handle, swapchain->hDC);
}
swapchain_invalidate(swapchain);
#endif
return hr;
}
struct wined3d_context *swapchain_create_context_for_thread(IWineD3DSwapChain *iface)
{
IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *) iface;
#ifndef VBOX_WITH_WDDM
struct wined3d_context **newArray;
#endif
struct wined3d_context *ctx;
TRACE("Creating a new context for swapchain %p, thread %d\n", This, GetCurrentThreadId());
#ifdef VBOX_WITH_WDDM
ERR("Should not be here");
#endif
if (!(ctx = context_create(This, (IWineD3DSurfaceImpl *)This->frontBuffer, This->ds_format
#ifdef VBOX_WITH_WDDM
, This->device->pHgsmi
#endif
)))
{
ERR("Failed to create a new context for the swapchain\n");
return NULL;
}
context_release(ctx);
#ifdef VBOX_WITH_WDDM
/* no need to do anything since context gets added to the device context list within the context_create call */
#else
newArray = HeapAlloc(GetProcessHeap(), 0, sizeof(*newArray) * (This->num_contexts + 1));
if(!newArray) {
ERR("Out of memory when trying to allocate a new context array\n");
context_destroy(This->device, ctx);
return NULL;
}
memcpy(newArray, This->context, sizeof(*newArray) * This->num_contexts);
HeapFree(GetProcessHeap(), 0, This->context);
newArray[This->num_contexts] = ctx;
This->context = newArray;
This->num_contexts++;
#endif
TRACE("Returning context %p\n", ctx);
return ctx;
}
void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height)
{
IWineD3DSurfaceImpl *surface = (IWineD3DSurfaceImpl *)context->current_rt;
/* The drawable size of an onscreen drawable is the surface size.
* (Actually: The window size, but the surface is created in window size) */
*width = surface->currentDesc.Width;
*height = surface->currentDesc.Height;
}