From ef4119029b08e94e31f1c59e54f6eead938d7b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Wed, 6 Feb 2008 20:35:06 +0100 Subject: [PATCH] d3d9: Implement the device lost state. --- dlls/d3d9/d3d9_private.h | 1 + dlls/d3d9/device.c | 41 +++++++++++++++++++++++++--------------- dlls/d3d9/tests/device.c | 27 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index ff3b9216323..1c4d7bfa4e0 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -184,6 +184,7 @@ typedef struct IDirect3DDevice9Impl IDirect3DVertexDeclaration9 **convertedDecls; unsigned int numConvertedDecls, declArraySize; + BOOL notreset; } IDirect3DDevice9Impl; diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index ca4200f0ef7..27940b465f8 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -85,11 +85,16 @@ static ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9 iface) { static HRESULT WINAPI IDirect3DDevice9Impl_TestCooperativeLevel(LPDIRECT3DDEVICE9 iface) { IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface; HRESULT hr; - TRACE("(%p) : Relay\n", This); + TRACE("(%p)\n", This); EnterCriticalSection(&d3d9_cs); hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice); LeaveCriticalSection(&d3d9_cs); + if(hr == WINED3D_OK && This->notreset) { + TRACE("D3D9 Device is marked not reset\n"); + hr = D3DERR_DEVICENOTRESET; + } + return hr; } @@ -331,6 +336,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9 iface, D3DP IWineD3DDevice_EnumResources(This->WineD3DDevice, reset_enum_callback, &resources_ok); if(!resources_ok) { WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n"); + This->notreset = TRUE; return WINED3DERR_INVALIDCALL; } @@ -352,21 +358,26 @@ static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9 iface, D3DP EnterCriticalSection(&d3d9_cs); hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters); LeaveCriticalSection(&d3d9_cs); + if(FAILED(hr)) { + This->notreset = TRUE; - pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; - pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight; - pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat; - pPresentationParameters->BackBufferCount = localParameters.BackBufferCount; - pPresentationParameters->MultiSampleType = localParameters.MultiSampleType; - pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality; - pPresentationParameters->SwapEffect = localParameters.SwapEffect; - pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow; - pPresentationParameters->Windowed = localParameters.Windowed; - pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil; - pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat; - pPresentationParameters->Flags = localParameters.Flags; - pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz; - pPresentationParameters->PresentationInterval = localParameters.PresentationInterval; + pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; + pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight; + pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat; + pPresentationParameters->BackBufferCount = localParameters.BackBufferCount; + pPresentationParameters->MultiSampleType = localParameters.MultiSampleType; + pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality; + pPresentationParameters->SwapEffect = localParameters.SwapEffect; + pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow; + pPresentationParameters->Windowed = localParameters.Windowed; + pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil; + pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat; + pPresentationParameters->Flags = localParameters.Flags; + pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz; + pPresentationParameters->PresentationInterval = localParameters.PresentationInterval; + } else { + This->notreset = FALSE; + } return hr; } diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 4c6f82eb981..0f1654de9d8 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -770,6 +770,8 @@ static void test_reset(void) skip("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr); goto cleanup; } + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after creation returned %#x\n", hr); width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); @@ -802,6 +804,8 @@ static void test_reset(void) d3dpp.BackBufferFormat = d3ddm.Format; hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successfull reset returned %#x\n", hr); ZeroMemory(&vp, sizeof(vp)); hr = IDirect3DDevice9_GetViewport(pDevice, &vp); @@ -843,6 +847,8 @@ static void test_reset(void) d3dpp.BackBufferHeight = 300; hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successfull reset returned %#x\n", hr); width = GetSystemMetrics(SM_CXSCREEN); height = GetSystemMetrics(SM_CYSCREEN); @@ -888,26 +894,38 @@ static void test_reset(void) ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %s\n", DXGetErrorString9(hr)); hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr); IDirect3DSurface9_Release(surface); /* Reset again to get the device out of the lost state */ hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successfull reset returned %#x\n", hr); /* Scratch, sysmem and managed pools are fine */ hr = IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice, 16, 16, D3DFMT_R5G6B5, D3DPOOL_SCRATCH, &surface, NULL); ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %s\n", DXGetErrorString9(hr)); hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successfull reset returned %#x\n", hr); IDirect3DSurface9_Release(surface); + hr = IDirect3DDevice9_CreateOffscreenPlainSurface(pDevice, 16, 16, D3DFMT_R5G6B5, D3DPOOL_SYSTEMMEM, &surface, NULL); ok(hr == D3D_OK, "IDirect3DDevice9_CreateOffscreenPlainSurface returned %s\n", DXGetErrorString9(hr)); hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successfull reset returned %#x\n", hr); IDirect3DSurface9_Release(surface); + hr = IDirect3DDevice9_CreateTexture(pDevice, 16, 16, 0, 0, D3DFMT_R5G6B5, D3DPOOL_MANAGED, &texture, NULL); ok(hr == D3D_OK, "IDirect3DDevice9_CreateTexture returned %s\n", DXGetErrorString9(hr)); hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successfull reset returned %#x\n", hr); IDirect3DTexture9_Release(texture); /* A reference held to an implicit surface causes failures as well */ @@ -915,9 +933,13 @@ static void test_reset(void) ok(hr == D3D_OK, "IDirect3DDevice9_GetBackBuffer returned %s\n", DXGetErrorString9(hr)); hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr); IDirect3DSurface9_Release(surface); hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3D_OK, "IDirect3DDevice9_Reset failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3D_OK, "IDirect3DDevice9_TestCooperativeLevel after a successfull reset returned %#x\n", hr); /* Shaders are fine as well */ hr = IDirect3DDevice9_CreateVertexShader(pDevice, simple_vs, &shader); @@ -934,6 +956,9 @@ static void test_reset(void) d3dpp.BackBufferHeight = 32; hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset to w=32, h=32, windowed=FALSE failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr); + ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.Windowed = FALSE; @@ -941,6 +966,8 @@ static void test_reset(void) d3dpp.BackBufferHeight = 600; hr = IDirect3DDevice9_Reset(pDevice, &d3dpp); ok(hr == D3DERR_INVALIDCALL, "IDirect3DDevice9_Reset to w=801, h=600, windowed=FALSE failed with %s\n", DXGetErrorString9(hr)); + hr = IDirect3DDevice9_TestCooperativeLevel(pDevice); + ok(hr == D3DERR_DEVICENOTRESET, "IDirect3DDevice9_TestCooperativeLevel after a failed reset returned %#x\n", hr); cleanup: if(pD3d) IDirect3D9_Release(pD3d);