2008-08-05 21:23:00 +02:00
|
|
|
/*
|
|
|
|
*IDirect3DSwapChain9 implementation
|
|
|
|
*
|
|
|
|
*Copyright 2002-2003 Jason Edmeades
|
|
|
|
*Copyright 2002-2003 Raphael Junqueira
|
|
|
|
*Copyright 2005 Oliver Stieber
|
2008-10-18 19:21:20 +02:00
|
|
|
*Copyright 2007-2008 Stefan Dösinger for CodeWeavers
|
2008-08-05 21:23:00 +02:00
|
|
|
*
|
|
|
|
*This library is free software; you can redistribute it and/or
|
|
|
|
*modify it under the terms of the GNU Lesser General Public
|
|
|
|
*License as published by the Free Software Foundation; either
|
|
|
|
*version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*This library is distributed in the hope that it will be useful,
|
|
|
|
*but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
*Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
*You should have received a copy of the GNU Lesser General Public
|
|
|
|
*License along with this library; if not, write to the Free Software
|
|
|
|
*Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wined3d_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(fps);
|
|
|
|
|
2009-09-16 08:37:15 +02:00
|
|
|
static void WINAPI IWineGDISwapChainImpl_Destroy(IWineD3DSwapChain *iface)
|
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
|
|
|
WINED3DDISPLAYMODE mode;
|
|
|
|
|
|
|
|
TRACE("Destroying swapchain %p\n", iface);
|
|
|
|
|
|
|
|
IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
|
|
|
|
|
|
|
|
/* release the ref to the front and back buffer parents */
|
2010-04-26 21:33:00 +02:00
|
|
|
if (This->front_buffer)
|
|
|
|
{
|
|
|
|
IWineD3DSurface_SetContainer((IWineD3DSurface *)This->front_buffer, NULL);
|
|
|
|
if (IWineD3DSurface_Release((IWineD3DSurface *)This->front_buffer) > 0)
|
2009-09-16 08:37:15 +02:00
|
|
|
{
|
|
|
|
WARN("(%p) Something's still holding the front buffer\n",This);
|
2008-08-05 21:23:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (This->back_buffers)
|
|
|
|
{
|
2008-12-01 23:19:43 +01:00
|
|
|
UINT i;
|
2010-04-26 21:33:01 +02:00
|
|
|
for (i = 0; i < This->presentParms.BackBufferCount; ++i)
|
|
|
|
{
|
|
|
|
IWineD3DSurface_SetContainer((IWineD3DSurface *)This->back_buffers[i], NULL);
|
|
|
|
if (IWineD3DSurface_Release((IWineD3DSurface *)This->back_buffers[i]))
|
2009-09-16 08:37:15 +02:00
|
|
|
{
|
|
|
|
WARN("(%p) Something's still holding the back buffer\n",This);
|
2008-08-05 21:23:00 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-26 21:33:01 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->back_buffers);
|
2008-08-05 21:23:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore the screen resolution if we rendered in fullscreen
|
|
|
|
* This will restore the screen resolution to what it was before creating the swapchain. In case of d3d8 and d3d9
|
|
|
|
* this will be the original desktop resolution. In case of d3d7 this will be a NOP because ddraw sets the resolution
|
|
|
|
* before starting up Direct3D, thus orig_width and orig_height will be equal to the modes in the presentation params
|
|
|
|
*/
|
2008-11-01 22:35:23 +01:00
|
|
|
if(This->presentParms.Windowed == FALSE && This->presentParms.AutoRestoreDisplayMode) {
|
2008-08-05 21:23:00 +02:00
|
|
|
mode.Width = This->orig_width;
|
|
|
|
mode.Height = This->orig_height;
|
|
|
|
mode.RefreshRate = 0;
|
|
|
|
mode.Format = This->orig_fmt;
|
2009-12-09 20:32:08 +01:00
|
|
|
IWineD3DDevice_SetDisplayMode((IWineD3DDevice *)This->device, 0, &mode);
|
2008-08-05 21:23:00 +02:00
|
|
|
}
|
|
|
|
|
2009-10-22 10:09:56 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->context);
|
2008-08-05 21:23:00 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* x11_copy_to_screen
|
|
|
|
*
|
|
|
|
* Helper function that blts the front buffer contents to the target window
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* This: Surface to copy from
|
|
|
|
* rc: Rectangle to copy
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2008-12-01 15:32:15 +01:00
|
|
|
void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc)
|
|
|
|
{
|
2010-04-26 21:33:00 +02:00
|
|
|
IWineD3DSurfaceImpl *front = This->front_buffer;
|
2008-08-05 21:23:00 +02:00
|
|
|
|
|
|
|
if(front->resource.usage & WINED3DUSAGE_RENDERTARGET) {
|
|
|
|
POINT offset = {0,0};
|
|
|
|
HWND hDisplayWnd;
|
|
|
|
HDC hDisplayDC;
|
|
|
|
HDC hSurfaceDC = 0;
|
|
|
|
RECT drawrect;
|
|
|
|
TRACE("(%p)->(%p): Copying to screen\n", front, rc);
|
|
|
|
|
|
|
|
hSurfaceDC = front->hDC;
|
|
|
|
|
2008-08-04 21:16:49 +02:00
|
|
|
hDisplayWnd = This->win_handle;
|
2008-08-05 21:23:00 +02:00
|
|
|
hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
|
|
|
|
if(rc) {
|
|
|
|
TRACE(" copying rect (%d,%d)->(%d,%d), offset (%d,%d)\n",
|
|
|
|
rc->left, rc->top, rc->right, rc->bottom, offset.x, offset.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Front buffer coordinates are screen coordinates. Map them to the destination
|
2008-08-04 21:11:22 +02:00
|
|
|
* window if not fullscreened
|
|
|
|
*/
|
|
|
|
if(This->presentParms.Windowed) {
|
2008-08-05 21:23:00 +02:00
|
|
|
ClientToScreen(hDisplayWnd, &offset);
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* FIXME: This doesn't work... if users really want to run
|
|
|
|
* X in 8bpp, then we need to call directly into display.drv
|
|
|
|
* (or Wine's equivalent), and force a private colormap
|
|
|
|
* without default entries. */
|
|
|
|
if (front->palette) {
|
|
|
|
SelectPalette(hDisplayDC, front->palette->hpal, FALSE);
|
|
|
|
RealizePalette(hDisplayDC); /* sends messages => deadlocks */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
drawrect.left = 0;
|
|
|
|
drawrect.right = front->currentDesc.Width;
|
|
|
|
drawrect.top = 0;
|
|
|
|
drawrect.bottom = front->currentDesc.Height;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* TODO: Support clippers */
|
|
|
|
if (front->clipper)
|
|
|
|
{
|
|
|
|
RECT xrc;
|
|
|
|
HWND hwnd = ((IWineD3DClipperImpl *) front->clipper)->hWnd;
|
|
|
|
if (hwnd && GetClientRect(hwnd,&xrc))
|
|
|
|
{
|
|
|
|
OffsetRect(&xrc,offset.x,offset.y);
|
|
|
|
IntersectRect(&drawrect,&drawrect,&xrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (rc) {
|
|
|
|
IntersectRect(&drawrect,&drawrect,rc);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Only use this if the caller did not pass a rectangle, since
|
|
|
|
* due to double locking this could be the wrong one ...
|
|
|
|
*/
|
|
|
|
if (front->lockedRect.left != front->lockedRect.right) {
|
|
|
|
IntersectRect(&drawrect,&drawrect,&front->lockedRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BitBlt(hDisplayDC,
|
|
|
|
drawrect.left-offset.x, drawrect.top-offset.y,
|
|
|
|
drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
|
|
|
|
hSurfaceDC,
|
|
|
|
drawrect.left, drawrect.top,
|
|
|
|
SRCCOPY);
|
|
|
|
ReleaseDC(hDisplayWnd, hDisplayDC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-29 05:34:32 +02:00
|
|
|
static HRESULT WINAPI IWineGDISwapChainImpl_SetDestWindowOverride(IWineD3DSwapChain *iface, HWND window) {
|
|
|
|
IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
|
|
|
|
|
|
|
|
This->win_handle = window;
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-05 21:23:00 +02:00
|
|
|
static HRESULT WINAPI IWineGDISwapChainImpl_Present(IWineD3DSwapChain *iface, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) {
|
|
|
|
IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *) iface;
|
|
|
|
IWineD3DSurfaceImpl *front, *back;
|
|
|
|
|
2010-04-26 21:33:01 +02:00
|
|
|
if (!This->back_buffers)
|
|
|
|
{
|
2008-08-05 21:23:00 +02:00
|
|
|
WARN("Swapchain doesn't have a backbuffer, returning WINED3DERR_INVALIDCALL\n");
|
|
|
|
return WINED3DERR_INVALIDCALL;
|
|
|
|
}
|
2010-04-26 21:33:00 +02:00
|
|
|
front = This->front_buffer;
|
2010-04-26 21:33:01 +02:00
|
|
|
back = This->back_buffers[0];
|
2008-08-05 21:23:00 +02:00
|
|
|
|
|
|
|
/* Flip the DC */
|
|
|
|
{
|
|
|
|
HDC tmp;
|
|
|
|
tmp = front->hDC;
|
|
|
|
front->hDC = back->hDC;
|
|
|
|
back->hDC = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the DIBsection */
|
|
|
|
{
|
|
|
|
HBITMAP tmp;
|
|
|
|
tmp = front->dib.DIBsection;
|
|
|
|
front->dib.DIBsection = back->dib.DIBsection;
|
|
|
|
back->dib.DIBsection = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flip the surface data */
|
|
|
|
{
|
|
|
|
void* tmp;
|
|
|
|
|
|
|
|
tmp = front->dib.bitmap_data;
|
|
|
|
front->dib.bitmap_data = back->dib.bitmap_data;
|
|
|
|
back->dib.bitmap_data = tmp;
|
|
|
|
|
|
|
|
tmp = front->resource.allocatedMemory;
|
|
|
|
front->resource.allocatedMemory = back->resource.allocatedMemory;
|
|
|
|
back->resource.allocatedMemory = tmp;
|
|
|
|
|
|
|
|
if(front->resource.heapMemory) {
|
|
|
|
ERR("GDI Surface %p has heap memory allocated\n", front);
|
|
|
|
}
|
|
|
|
if(back->resource.heapMemory) {
|
|
|
|
ERR("GDI Surface %p has heap memory allocated\n", back);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* client_memory should not be different, but just in case */
|
|
|
|
{
|
|
|
|
BOOL tmp;
|
|
|
|
tmp = front->dib.client_memory;
|
|
|
|
front->dib.client_memory = back->dib.client_memory;
|
|
|
|
back->dib.client_memory = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FPS support */
|
|
|
|
if (TRACE_ON(fps))
|
|
|
|
{
|
|
|
|
static long prev_time, frames;
|
|
|
|
|
|
|
|
DWORD time = GetTickCount();
|
|
|
|
frames++;
|
|
|
|
/* every 1.5 seconds */
|
|
|
|
if (time - prev_time > 1500) {
|
|
|
|
TRACE_(fps)("@ approx %.2ffps\n", 1000.0*frames/(time - prev_time));
|
|
|
|
prev_time = time;
|
|
|
|
frames = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x11_copy_to_screen(This, NULL);
|
|
|
|
|
|
|
|
return WINED3D_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl =
|
|
|
|
{
|
|
|
|
/* IUnknown */
|
|
|
|
IWineD3DBaseSwapChainImpl_QueryInterface,
|
|
|
|
IWineD3DBaseSwapChainImpl_AddRef,
|
|
|
|
IWineD3DBaseSwapChainImpl_Release,
|
|
|
|
/* IWineD3DSwapChain */
|
|
|
|
IWineD3DBaseSwapChainImpl_GetParent,
|
|
|
|
IWineGDISwapChainImpl_Destroy,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetDevice,
|
|
|
|
IWineGDISwapChainImpl_Present,
|
2008-07-29 05:34:32 +02:00
|
|
|
IWineGDISwapChainImpl_SetDestWindowOverride,
|
2008-08-05 21:23:00 +02:00
|
|
|
IWineD3DBaseSwapChainImpl_GetFrontBufferData,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetBackBuffer,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetRasterStatus,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetDisplayMode,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetPresentParameters,
|
|
|
|
IWineD3DBaseSwapChainImpl_SetGammaRamp,
|
|
|
|
IWineD3DBaseSwapChainImpl_GetGammaRamp
|
|
|
|
};
|