ddraw: Use real handles for state blocks.

This commit is contained in:
Stefan Dösinger 2006-10-14 23:58:42 +02:00 committed by Alexandre Julliard
parent 2e5628df3f
commit 1c86290bd5
2 changed files with 72 additions and 11 deletions

View File

@ -273,7 +273,8 @@ typedef enum
DDrawHandle_Unknown = 0, DDrawHandle_Unknown = 0,
DDrawHandle_Texture = 1, DDrawHandle_Texture = 1,
DDrawHandle_Material = 2, DDrawHandle_Material = 2,
DDrawHandle_Matrix = 3 DDrawHandle_Matrix = 3,
DDrawHandle_StateBlock = 4
} DDrawHandleTypes; } DDrawHandleTypes;
struct HandleEntry struct HandleEntry

View File

@ -352,6 +352,15 @@ IDirect3DDeviceImpl_7_Release(IDirect3DDevice7 *iface)
} }
break; break;
case DDrawHandle_StateBlock:
{
/* No fixme here because this might happen because of sloppy apps */
WARN("Leftover stateblock handle %d, deleting\n", i + 1);
IDirect3DDevice7_DeleteStateBlock(ICOM_INTERFACE(This, IDirect3DDevice7),
i + 1);
}
break;
default: default:
FIXME("Unknown handle %d not unset properly\n", i + 1); FIXME("Unknown handle %d not unset properly\n", i + 1);
} }
@ -4255,8 +4264,7 @@ IDirect3DDeviceImpl_7_BeginStateBlock(IDirect3DDevice7 *iface)
* IDirect3DDevice7::EndStateBlock * IDirect3DDevice7::EndStateBlock
* *
* Stops recording to a state block and returns the created stateblock * Stops recording to a state block and returns the created stateblock
* handle. The d3d7 stateblock handles are the interface pointers of the * handle.
* IWineD3DStateBlock interface
* *
* Version 7 * Version 7
* *
@ -4278,10 +4286,20 @@ IDirect3DDeviceImpl_7_EndStateBlock(IDirect3DDevice7 *iface,
TRACE("(%p)->(%p): Relay!\n", This, BlockHandle); TRACE("(%p)->(%p): Relay!\n", This, BlockHandle);
if(!BlockHandle) if(!BlockHandle)
{
WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
}
*BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
if(!*BlockHandle)
{
ERR("Cannot get a handle number for the stateblock\n");
return DDERR_OUTOFMEMORY;
}
This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice, hr = IWineD3DDevice_EndStateBlock(This->wineD3DDevice,
(IWineD3DStateBlock **) BlockHandle); (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr);
return hr_ddraw_from_wined3d(hr); return hr_ddraw_from_wined3d(hr);
} }
@ -4339,10 +4357,18 @@ IDirect3DDeviceImpl_7_ApplyStateBlock(IDirect3DDevice7 *iface,
HRESULT hr; HRESULT hr;
TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle); TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
if(!BlockHandle) if(!BlockHandle || BlockHandle > This->numHandles)
{
WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
return D3DERR_INVALIDSTATEBLOCK; return D3DERR_INVALIDSTATEBLOCK;
}
if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
{
WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
return D3DERR_INVALIDSTATEBLOCK;
}
hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) BlockHandle); hr = IWineD3DStateBlock_Apply((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
return hr_ddraw_from_wined3d(hr); return hr_ddraw_from_wined3d(hr);
} }
@ -4370,10 +4396,18 @@ IDirect3DDeviceImpl_7_CaptureStateBlock(IDirect3DDevice7 *iface,
HRESULT hr; HRESULT hr;
TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle); TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
if(BlockHandle == 0) if(BlockHandle == 0 || BlockHandle > This->numHandles)
{
WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
return D3DERR_INVALIDSTATEBLOCK; return D3DERR_INVALIDSTATEBLOCK;
}
if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
{
WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
return D3DERR_INVALIDSTATEBLOCK;
}
hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) BlockHandle); hr = IWineD3DStateBlock_Capture((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
return hr_ddraw_from_wined3d(hr); return hr_ddraw_from_wined3d(hr);
} }
@ -4397,12 +4431,27 @@ IDirect3DDeviceImpl_7_DeleteStateBlock(IDirect3DDevice7 *iface,
DWORD BlockHandle) DWORD BlockHandle)
{ {
ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface); ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
ULONG ref;
TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle); TRACE("(%p)->(%08x): Relay!\n", This, BlockHandle);
if(BlockHandle == 0) if(BlockHandle == 0 || BlockHandle > This->numHandles)
{
WARN("Out of range handle %d, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
return D3DERR_INVALIDSTATEBLOCK; return D3DERR_INVALIDSTATEBLOCK;
}
if(This->Handles[BlockHandle - 1].type != DDrawHandle_StateBlock)
{
WARN("Handle %d is not a stateblock, returning D3DERR_INVALIDSTATEBLOCK\n", BlockHandle);
return D3DERR_INVALIDSTATEBLOCK;
}
IWineD3DStateBlock_Release((IWineD3DStateBlock *) BlockHandle); ref = IWineD3DStateBlock_Release((IWineD3DStateBlock *) This->Handles[BlockHandle - 1].ptr);
if(ref)
{
ERR("Something is still holding the stateblock %p(Handle %d). Ref = %d\n", This->Handles[BlockHandle - 1].ptr, BlockHandle, ref);
}
This->Handles[BlockHandle - 1].ptr = NULL;
This->Handles[BlockHandle - 1].type = DDrawHandle_Unknown;
return D3D_OK; return D3D_OK;
} }
@ -4433,12 +4482,23 @@ IDirect3DDeviceImpl_7_CreateStateBlock(IDirect3DDevice7 *iface,
TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle); TRACE("(%p)->(%08x,%p)!\n", This, Type, BlockHandle);
if(!BlockHandle) if(!BlockHandle)
{
WARN("BlockHandle == NULL, returning DDERR_INVALIDPARAMS\n");
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
}
*BlockHandle = IDirect3DDeviceImpl_CreateHandle(This);
if(!*BlockHandle)
{
ERR("Cannot get a handle number for the stateblock\n");
return DDERR_OUTOFMEMORY;
}
This->Handles[*BlockHandle - 1].type = DDrawHandle_StateBlock;
/* The D3DSTATEBLOCKTYPE enum is fine here */ /* The D3DSTATEBLOCKTYPE enum is fine here */
hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice, hr = IWineD3DDevice_CreateStateBlock(This->wineD3DDevice,
Type, Type,
(IWineD3DStateBlock **) BlockHandle, (IWineD3DStateBlock **) &This->Handles[*BlockHandle - 1].ptr,
NULL /* Parent, hope that works */); NULL /* Parent, hope that works */);
return hr_ddraw_from_wined3d(hr); return hr_ddraw_from_wined3d(hr);
} }