Commit e902cd11 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Swapchain and back buffer corrections + tests.

parent 6df2c04f
......@@ -89,6 +89,7 @@ HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface,
IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
IWineD3DSurface_Release(mySurface);
}
/* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
return hrc;
}
......@@ -172,6 +173,11 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE
object->ref = 1;
object->lpVtbl = &Direct3DSwapChain9_Vtbl;
/* The back buffer count is set to one if it's 0 */
if(pPresentationParameters->BackBufferCount == 0) {
pPresentationParameters->BackBufferCount = 1;
}
/* Allocate an associated WineD3DDevice object */
localParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
localParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
......@@ -214,6 +220,8 @@ HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9 iface, UINT
if (hrc == D3D_OK && NULL != swapchain) {
IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
IWineD3DSwapChain_Release(swapchain);
} else {
*pSwapChain = NULL;
}
return hrc;
}
......
/*
* Copyright (C) 2006 Vitaliy Margolen
* Copyright (C) 2006 Stefan Dsinger(For CodeWeavers)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -37,6 +38,150 @@ static int get_refcount(IUnknown *object)
trace("%s failed: %s\n", c, DXGetErrorString9(r)); \
}
void test_swapchain(void)
{
HRESULT hr;
HWND hwnd = NULL;
IDirect3D9 *pD3d = NULL;
IDirect3DDevice9 *pDevice = NULL;
IDirect3DSwapChain9 *swapchain0 = NULL;
IDirect3DSwapChain9 *swapchain1 = NULL;
IDirect3DSwapChain9 *swapchain2 = NULL;
IDirect3DSwapChain9 *swapchain3 = NULL;
IDirect3DSwapChain9 *swapchainX = NULL;
IDirect3DSurface9 *backbuffer = NULL;
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
pD3d = pDirect3DCreate9( D3D_SDK_VERSION );
ok(pD3d != NULL, "Failed to create IDirect3D9 object\n");
hwnd = CreateWindow( "static", "d3d9_test", WS_OVERLAPPEDWINDOW, 100, 100, 160, 160, NULL, NULL, NULL, NULL );
ok(hwnd != NULL, "Failed to create window\n");
if (!pD3d || !hwnd) goto cleanup;
IDirect3D9_GetAdapterDisplayMode( pD3d, D3DADAPTER_DEFAULT, &d3ddm );
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferCount = 0;
hr = IDirect3D9_CreateDevice( pD3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDevice );
ok(SUCCEEDED(hr), "Failed to create IDirect3D9Device (%s)\n", DXGetErrorString9(hr));
if (FAILED(hr)) goto cleanup;
/* Check if the back buffer count was modified */
ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
/* Get the implicit swapchain */
hr = IDirect3DDevice9_GetSwapChain(pDevice, 0, &swapchain0);
ok(SUCCEEDED(hr), "Failed to get the impicit swapchain (%s)\n", DXGetErrorString9(hr));
if(swapchain0) IDirect3DSwapChain9_Release(swapchain0);
/* Check if there is a back buffer */
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
ok(SUCCEEDED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer != NULL, "The back buffer is NULL\n");
if(backbuffer) IDirect3DSurface9_Release(backbuffer);
/* Try to get a nonexistant swapchain */
hr = IDirect3DDevice9_GetSwapChain(pDevice, 1, &swapchainX);
ok(hr == D3DERR_INVALIDCALL, "GetSwapChain on an non-existant swapchain returned (%s)\n", DXGetErrorString9(hr));
ok(swapchainX == NULL, "Swapchain 1 is %p\n", swapchainX);
if(swapchainX) IDirect3DSwapChain9_Release(swapchainX);
/* Create a bunch of swapchains */
d3dpp.BackBufferCount = 0;
hr = IDirect3DDevice9_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain1);
ok(SUCCEEDED(hr), "Failed to create a swapchain (%s)\n", DXGetErrorString9(hr));
ok(d3dpp.BackBufferCount == 1, "The back buffer count in the presentparams struct is %d\n", d3dpp.BackBufferCount);
d3dpp.BackBufferCount = 1;
hr = IDirect3DDevice9_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain2);
ok(SUCCEEDED(hr), "Failed to create a swapchain (%s)\n", DXGetErrorString9(hr));
/* Unsupported by wine for now */
d3dpp.BackBufferCount = 2;
hr = IDirect3DDevice9_CreateAdditionalSwapChain(pDevice, &d3dpp, &swapchain3);
todo_wine ok(SUCCEEDED(hr), "Failed to create a swapchain (%s)\n", DXGetErrorString9(hr));
if(SUCCEEDED(hr)) {
/* Swapchain 3, created with backbuffercount 2 */
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 0, 0, &backbuffer);
ok(SUCCEEDED(hr), "Failed to get the 1st back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 1, 0, &backbuffer);
ok(SUCCEEDED(hr), "Failed to get the 2nd back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 2, 0, &backbuffer);
ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %s\n", DXGetErrorString9(hr));
ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain3, 3, 0, &backbuffer);
ok(FAILED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
}
/* Check the back buffers of the swapchains */
/* Swapchain 1, created with backbuffercount 0 */
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain1, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
ok(SUCCEEDED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer != NULL, "The back buffer is NULL (%s)\n", DXGetErrorString9(hr));
if(backbuffer) IDirect3DSurface9_Release(backbuffer);
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain1, 1, 0, &backbuffer);
ok(FAILED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
/* Swapchain 2 - created with backbuffercount 1 */
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain2, 0, 0, &backbuffer);
ok(SUCCEEDED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer != NULL && backbuffer != (void *) 0xdeadbeef, "The back buffer is %p\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain2, 1, 0, &backbuffer);
ok(hr == D3DERR_INVALIDCALL, "GetBackBuffer returned %s\n", DXGetErrorString9(hr));
ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
backbuffer = (void *) 0xdeadbeef;
hr = IDirect3DSwapChain9_GetBackBuffer(swapchain2, 2, 0, &backbuffer);
ok(FAILED(hr), "Failed to get the back buffer (%s)\n", DXGetErrorString9(hr));
ok(backbuffer == (void *) 0xdeadbeef, "The back buffer pointer was modified (%p)\n", backbuffer);
if(backbuffer && backbuffer != (void *) 0xdeadbeef) IDirect3DSurface9_Release(backbuffer);
/* Try getSwapChain on a manually created swapchain
* it should fail, apparently GetSwapChain only returns implicit swapchains
*/
swapchainX = (void *) 0xdeadbeef;
hr = IDirect3DDevice9_GetSwapChain(pDevice, 1, &swapchainX);
ok(hr == D3DERR_INVALIDCALL, "Failed to get the secound swapchain (%s)\n", DXGetErrorString9(hr));
ok(swapchainX == NULL, "The swapchain pointer is %p\n", swapchainX);
if(swapchainX && swapchainX != (void *) 0xdeadbeef ) IDirect3DSwapChain9_Release(swapchainX);
cleanup:
if(swapchain1) IDirect3DSwapChain9_Release(swapchain1);
if(swapchain2) IDirect3DSwapChain9_Release(swapchain2);
if(swapchain3) IDirect3DSwapChain9_Release(swapchain3);
if(pDevice) IDirect3DDevice9_Release(pDevice);
if(pD3d) IDirect3DDevice9_Release(pD3d);
DestroyWindow( hwnd );
}
void test_refcount(void)
{
HRESULT hr;
......@@ -195,6 +340,7 @@ START_TEST(device)
pDirect3DCreate9 = (void *)GetProcAddress( d3d9_handle, "Direct3DCreate9" );
if (pDirect3DCreate9)
{
test_swapchain();
test_refcount();
}
}
......@@ -90,9 +90,6 @@ ULONG WINAPI IWineD3DSwapChainImpl_Release(IWineD3DSwapChain *iface) {
if (refCount == 0) {
IUnknown* bufferParent;
/* tell the device that we've been released */
IWineD3DDevice_SwapChainReleased((IWineD3DDevice *)This->wineD3DDevice, iface);
/* release the ref to the front and back buffer parents */
if(This->frontBuffer) {
IWineD3DSurface_SetContainer(This->frontBuffer, 0);
......@@ -377,7 +374,11 @@ HRESULT WINAPI IWineD3DSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UIN
TRACE("(%p) : BackBuf %d Type %d returning %p\n", This, iBackBuffer, Type, *ppBackBuffer);
if (iBackBuffer > This->presentParms.BackBufferCount - 1) {
FIXME("Only one backBuffer currently supported\n");
TRACE("Back buffer count out of range\n");
/* Native d3d9 doesn't set NULL here, just as wine's d3d9. But set it here
* in wined3d to avoid problems in other libs
*/
*ppBackBuffer = NULL;
return WINED3DERR_INVALIDCALL;
}
......
......@@ -444,11 +444,6 @@ typedef struct IWineD3DImpl
extern const IWineD3DVtbl IWineD3D_Vtbl;
typedef struct SwapChainList {
IWineD3DSwapChain *swapchain;
struct SwapChainList *next;
} SwapChainList;
/** Hacked out start of a context manager!! **/
typedef struct glContext {
int Width;
......@@ -529,7 +524,8 @@ typedef struct IWineD3DDeviceImpl
UINT adapterNo;
D3DDEVTYPE devType;
SwapChainList *swapchains;
IWineD3DSwapChain **swapchains;
uint NumberOfSwapChains;
ResourceList *resources; /* a linked list to track resources created by the device */
......
......@@ -504,7 +504,6 @@ DECLARE_INTERFACE_(IWineD3DDevice,IWineD3DBase)
STDMETHOD(GetFrontBufferData)(THIS_ UINT iSwapChain,struct IWineD3DSurface* pSurface) PURE;
/*** Internal use IWineD3Device methods ***/
STDMETHOD_(void, SetupTextureStates)(THIS_ DWORD Stage, DWORD Flags);
STDMETHOD_(void, SwapChainReleased)(THIS_ struct IWineD3DSwapChain *swapChain);
/*** object tracking ***/
STDMETHOD_(void, ResourceReleased)(THIS_ struct IWineD3DResource *resource);
};
......@@ -652,7 +651,6 @@ DECLARE_INTERFACE_(IWineD3DDevice,IWineD3DBase)
#define IWineD3DDevice_GetRenderTargetData(p,a,b) (p)->lpVtbl->GetRenderTargetData(p,a,b)
#define IWineD3DDevice_GetFrontBufferData(p,a,b) (p)->lpVtbl->GetFrontBufferData(p,a,b)
#define IWineD3DDevice_SetupTextureStates(p,a,b) (p)->lpVtbl->SetupTextureStates(p,a,b)
#define IWineD3DDevice_SwapChainReleased(p,a) (p)->lpVtbl->SwapChainReleased(p,a)
#define IWineD3DDevice_ResourceReleased(p,a) (p)->lpVtbl->ResourceReleased(p,a)
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment