Commit fd3d769a authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3d9: Fix locking.

It appears there are some calls to wined3d missing critical sections.
parent 435b528e
......@@ -513,6 +513,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3
* Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
* below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
*/
EnterCriticalSection(&d3d9_cs);
IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL);
for(i = 0; i < 16; i++) {
IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
......@@ -525,6 +527,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3
if(!resources_ok) {
WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
This->notreset = TRUE;
LeaveCriticalSection(&d3d9_cs);
return WINED3DERR_INVALIDCALL;
}
......@@ -544,9 +547,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3
localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
localParameters.AutoRestoreDisplayMode = TRUE;
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
LeaveCriticalSection(&d3d9_cs);
if(FAILED(hr)) {
This->notreset = TRUE;
......@@ -568,6 +569,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3
This->notreset = FALSE;
}
LeaveCriticalSection(&d3d9_cs);
return hr;
}
......@@ -672,9 +675,11 @@ static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UIN
TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
EnterCriticalSection(&d3d9_cs);
hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
MultiSample, MultisampleQuality, pSharedHandle, SURFACE_OPENGL, (IUnknown *)object);
LeaveCriticalSection(&d3d9_cs);
if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
......@@ -699,10 +704,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE
HRESULT hr;
TRACE("Relay\n");
/* Is this correct? */
EnterCriticalSection(&d3d9_cs);
hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
......@@ -713,11 +715,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(LPDIRECT3
HRESULT hr;
TRACE("Relay\n");
EnterCriticalSection(&d3d9_cs);
hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/* Lockable */,Discard, 0/* Level */
,ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_DEPTHSTENCIL,
D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
......@@ -796,19 +796,21 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(LPDIRECT3DDEVICE9EX iface
desc.Usage = &usage;
desc.Pool = &pool;
desc.Type = &restype;
EnterCriticalSection(&d3d9_cs);
IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
/* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
* in D3DPOOL_DEFAULT
*/
if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != D3DPOOL_DEFAULT || restype != D3DRTYPE_SURFACE)) {
LeaveCriticalSection(&d3d9_cs);
WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
return D3DERR_INVALIDCALL;
}
/* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
/* Note: D3DRECT is compatible with WINED3DRECT */
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
LeaveCriticalSection(&d3d9_cs);
return hr;
......@@ -828,9 +830,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateOffscreenPlainSurface(LPDIREC
Why, their always lockable?
should I change the usage to dynamic?
*/
EnterCriticalSection(&d3d9_cs);
hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/*Loackable*/,FALSE/*Discard*/,0/*Level*/ , ppSurface,D3DRTYPE_SURFACE, 0/*Usage (undefined/none)*/,(WINED3DPOOL) Pool,D3DMULTISAMPLE_NONE,0/*MultisampleQuality*/,pSharedHandle);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
......@@ -958,10 +959,16 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(LPDIRECT3DDEVICE9EX if
static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
TRACE("(%p) Relay\n" , This);
EnterCriticalSection(&d3d9_cs);
/* Note: D3DMATRIX is compatible with WINED3DMATRIX */
return IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(LPDIRECT3DDEVICE9EX iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix) {
......@@ -1519,21 +1526,19 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetFVF(LPDIRECT3DDEVICE9EX iface, DWO
}
EnterCriticalSection(&d3d9_cs);
decl = getConvertedDecl(This, FVF);
LeaveCriticalSection(&d3d9_cs);
if (!decl)
{
/* Any situation when this should happen, except out of memory? */
ERR("Failed to create a converted vertex declaration\n");
LeaveCriticalSection(&d3d9_cs);
return D3DERR_DRIVERINTERNALERROR;
}
hr = IDirect3DDevice9Impl_SetVertexDeclaration(iface, decl);
if (FAILED(hr)) ERR("Failed to set vertex declaration\n");
LeaveCriticalSection(&d3d9_cs);
return hr;
}
......
......@@ -165,7 +165,10 @@ static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9EX iface,
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
HRESULT hr;
EnterCriticalSection(&d3d9_cs);
hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
LeaveCriticalSection(&d3d9_cs);
if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
return hr;
......
......@@ -239,9 +239,11 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface,
object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
object->ref = 1;
TRACE("Calling wined3d create index buffer\n");
EnterCriticalSection(&d3d9_cs);
hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
wined3dformat_from_d3dformat(Format), (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer,
pSharedHandle, (IUnknown *)object);
LeaveCriticalSection(&d3d9_cs);
if (hrc != D3D_OK) {
/* free up object */
......
......@@ -205,8 +205,15 @@ HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9EX
HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT Register, float* pConstantData, UINT Vector4fCount) {
IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
HRESULT hr;
TRACE("(%p) Relay\n", This);
return IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT Register, CONST int* pConstantData, UINT Vector4iCount) {
......
......@@ -74,8 +74,15 @@ static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface)
/* IDirect3DSwapChain9 parts follow: */
static HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
HRESULT hr;
TRACE("(%p) Relay\n", This);
return IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
......
......@@ -87,8 +87,15 @@ static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFE
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
HRESULT hr;
TRACE("(%p) Relay\n", This);
return IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
static HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
......
......@@ -72,7 +72,9 @@ static ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
TRACE("(%p) : ReleaseRef to %d\n", This, ref);
if (ref == 0) {
EnterCriticalSection(&d3d9_cs);
IWineD3DVolume_Release(This->wineD3DVolume);
LeaveCriticalSection(&d3d9_cs);
HeapFree(GetProcessHeap(), 0, This);
}
......@@ -85,28 +87,62 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, ID
IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
IWineD3DDevice *myDevice = NULL;
TRACE("iface %p, ppDevice %p\n", iface, ppDevice);
EnterCriticalSection(&d3d9_cs);
IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
IWineD3DDevice_Release(myDevice);
LeaveCriticalSection(&d3d9_cs);
return D3D_OK;
}
static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
HRESULT hr;
TRACE("(%p) Relay\n", This);
return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
HRESULT hr;
TRACE("(%p) Relay\n", This);
return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
HRESULT hr;
TRACE("(%p) Relay\n", This);
return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
......@@ -147,8 +183,12 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DV
wined3ddesc.Height = &pDesc->Height;
wined3ddesc.Depth = &pDesc->Depth;
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
LeaveCriticalSection(&d3d9_cs);
if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
return hr;
......@@ -156,14 +196,33 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DV
static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
HRESULT hr;
TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
return IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume, (CONST WINED3DBOX *)pBox, Flags);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume,
(const WINED3DBOX *)pBox, Flags);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
HRESULT hr;
TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
EnterCriticalSection(&d3d9_cs);
hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
LeaveCriticalSection(&d3d9_cs);
return hr;
}
const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
......
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