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

ddraw: Hold the Lock in IDirect3DViewport methods.

parent f45684d5
...@@ -252,8 +252,11 @@ IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface, ...@@ -252,8 +252,11 @@ IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface,
ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
DWORD dwSize; DWORD dwSize;
TRACE("(%p/%p)->(%p)\n", This, iface, lpData); TRACE("(%p/%p)->(%p)\n", This, iface, lpData);
EnterCriticalSection(&ddraw_cs);
if (This->use_vp2 != 0) { if (This->use_vp2 != 0) {
ERR(" Requesting to get a D3DVIEWPORT struct where a D3DVIEWPORT2 was set !\n"); ERR(" Requesting to get a D3DVIEWPORT struct where a D3DVIEWPORT2 was set !\n");
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
dwSize = lpData->dwSize; dwSize = lpData->dwSize;
...@@ -264,6 +267,7 @@ IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface, ...@@ -264,6 +267,7 @@ IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface,
TRACE(" returning D3DVIEWPORT :\n"); TRACE(" returning D3DVIEWPORT :\n");
_dump_D3DVIEWPORT(lpData); _dump_D3DVIEWPORT(lpData);
} }
LeaveCriticalSection(&ddraw_cs);
return DD_OK; return DD_OK;
} }
...@@ -294,6 +298,7 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface, ...@@ -294,6 +298,7 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface,
_dump_D3DVIEWPORT(lpData); _dump_D3DVIEWPORT(lpData);
} }
EnterCriticalSection(&ddraw_cs);
This->use_vp2 = 0; This->use_vp2 = 0;
memset(&(This->viewports.vp1), 0, sizeof(This->viewports.vp1)); memset(&(This->viewports.vp1), 0, sizeof(This->viewports.vp1));
memcpy(&(This->viewports.vp1), lpData, lpData->dwSize); memcpy(&(This->viewports.vp1), lpData, lpData->dwSize);
...@@ -310,6 +315,7 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface, ...@@ -310,6 +315,7 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface,
This->activate(This); This->activate(This);
if(current_viewport) IDirect3DViewport3_Release(current_viewport); if(current_viewport) IDirect3DViewport3_Release(current_viewport);
} }
LeaveCriticalSection(&ddraw_cs);
return DD_OK; return DD_OK;
} }
...@@ -384,14 +390,17 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface, ...@@ -384,14 +390,17 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface,
ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
TRACE("(%p)->(%d)\n", This, (DWORD) hMat); TRACE("(%p)->(%d)\n", This, (DWORD) hMat);
EnterCriticalSection(&ddraw_cs);
if(hMat && hMat > This->ddraw->d3ddevice->numHandles) if(hMat && hMat > This->ddraw->d3ddevice->numHandles)
{ {
WARN("Specified Handle %d out of range\n", hMat); WARN("Specified Handle %d out of range\n", hMat);
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
else if(hMat && This->ddraw->d3ddevice->Handles[hMat - 1].type != DDrawHandle_Material) else if(hMat && This->ddraw->d3ddevice->Handles[hMat - 1].type != DDrawHandle_Material)
{ {
WARN("Handle %d is not a material handle\n", hMat); WARN("Handle %d is not a material handle\n", hMat);
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
...@@ -410,6 +419,7 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface, ...@@ -410,6 +419,7 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface,
TRACE("Setting background to NULL\n"); TRACE("Setting background to NULL\n");
} }
LeaveCriticalSection(&ddraw_cs);
return D3D_OK; return D3D_OK;
} }
...@@ -434,6 +444,7 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface, ...@@ -434,6 +444,7 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface,
ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
TRACE("(%p)->(%p,%p)\n", This, lphMat, lpValid); TRACE("(%p)->(%p,%p)\n", This, lphMat, lpValid);
EnterCriticalSection(&ddraw_cs);
if(lpValid) if(lpValid)
{ {
*lpValid = This->background != NULL; *lpValid = This->background != NULL;
...@@ -449,6 +460,7 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface, ...@@ -449,6 +460,7 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface,
*lphMat = 0; *lphMat = 0;
} }
} }
LeaveCriticalSection(&ddraw_cs);
return D3D_OK; return D3D_OK;
} }
...@@ -523,12 +535,15 @@ IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface, ...@@ -523,12 +535,15 @@ IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface,
{ {
ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
DWORD color = 0x00000000; DWORD color = 0x00000000;
HRESULT hr;
TRACE("(%p/%p)->(%08x,%p,%08x)\n", This, iface, dwCount, lpRects, dwFlags); TRACE("(%p/%p)->(%08x,%p,%08x)\n", This, iface, dwCount, lpRects, dwFlags);
if (This->active_device == NULL) { if (This->active_device == NULL) {
ERR(" Trying to clear a viewport not attached to a device !\n"); ERR(" Trying to clear a viewport not attached to a device !\n");
return D3DERR_VIEWPORTHASNODEVICE; return D3DERR_VIEWPORTHASNODEVICE;
} }
EnterCriticalSection(&ddraw_cs);
if (dwFlags & D3DCLEAR_TARGET) { if (dwFlags & D3DCLEAR_TARGET) {
if (This->background == NULL) { if (This->background == NULL) {
ERR(" Trying to clear the color buffer without background material !\n"); ERR(" Trying to clear the color buffer without background material !\n");
...@@ -541,13 +556,15 @@ IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface, ...@@ -541,13 +556,15 @@ IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface,
} }
} }
return IDirect3DDevice7_Clear(ICOM_INTERFACE(This->active_device, IDirect3DDevice7), hr = IDirect3DDevice7_Clear(ICOM_INTERFACE(This->active_device, IDirect3DDevice7),
dwCount, dwCount,
lpRects, lpRects,
dwFlags & (D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET), dwFlags & (D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET),
color, color,
1.0, 1.0,
0x00000000); 0x00000000);
LeaveCriticalSection(&ddraw_cs);
return hr;
} }
/***************************************************************************** /*****************************************************************************
...@@ -575,8 +592,12 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface, ...@@ -575,8 +592,12 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface,
TRACE("(%p)->(%p)\n", This, lpDirect3DLight); TRACE("(%p)->(%p)\n", This, lpDirect3DLight);
EnterCriticalSection(&ddraw_cs);
if (This->num_lights >= 8) if (This->num_lights >= 8)
{
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
}
/* Find a light number and update both light and viewports objects accordingly */ /* Find a light number and update both light and viewports objects accordingly */
while(map&1) { while(map&1) {
...@@ -599,6 +620,7 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface, ...@@ -599,6 +620,7 @@ IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface,
lpDirect3DLightImpl->activate(lpDirect3DLightImpl); lpDirect3DLightImpl->activate(lpDirect3DLightImpl);
} }
LeaveCriticalSection(&ddraw_cs);
return D3D_OK; return D3D_OK;
} }
...@@ -624,6 +646,8 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface, ...@@ -624,6 +646,8 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface,
IDirect3DLightImpl *cur_light, *prev_light = NULL; IDirect3DLightImpl *cur_light, *prev_light = NULL;
TRACE("(%p)->(%p)\n", This, lpDirect3DLight); TRACE("(%p)->(%p)\n", This, lpDirect3DLight);
EnterCriticalSection(&ddraw_cs);
cur_light = This->lights; cur_light = This->lights;
while (cur_light != NULL) { while (cur_light != NULL) {
if (cur_light == lpDirect3DLightImpl) { if (cur_light == lpDirect3DLightImpl) {
...@@ -634,11 +658,14 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface, ...@@ -634,11 +658,14 @@ IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *iface,
cur_light->active_viewport = NULL; cur_light->active_viewport = NULL;
This->num_lights--; This->num_lights--;
This->map_lights &= ~(1<<lpDirect3DLightImpl->dwLightIndex); This->map_lights &= ~(1<<lpDirect3DLightImpl->dwLightIndex);
LeaveCriticalSection(&ddraw_cs);
return D3D_OK; return D3D_OK;
} }
prev_light = cur_light; prev_light = cur_light;
cur_light = cur_light->next; cur_light = cur_light->next;
} }
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
...@@ -693,8 +720,11 @@ IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface, ...@@ -693,8 +720,11 @@ IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface,
ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
DWORD dwSize; DWORD dwSize;
TRACE("(%p)->(%p)\n", This, lpData); TRACE("(%p)->(%p)\n", This, lpData);
EnterCriticalSection(&ddraw_cs);
if (This->use_vp2 != 1) { if (This->use_vp2 != 1) {
ERR(" Requesting to get a D3DVIEWPORT2 struct where a D3DVIEWPORT was set !\n"); ERR(" Requesting to get a D3DVIEWPORT2 struct where a D3DVIEWPORT was set !\n");
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
} }
dwSize = lpData->dwSize; dwSize = lpData->dwSize;
...@@ -706,6 +736,7 @@ IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface, ...@@ -706,6 +736,7 @@ IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface,
_dump_D3DVIEWPORT2(lpData); _dump_D3DVIEWPORT2(lpData);
} }
LeaveCriticalSection(&ddraw_cs);
return D3D_OK; return D3D_OK;
} }
...@@ -734,6 +765,7 @@ IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface, ...@@ -734,6 +765,7 @@ IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface,
_dump_D3DVIEWPORT2(lpData); _dump_D3DVIEWPORT2(lpData);
} }
EnterCriticalSection(&ddraw_cs);
This->use_vp2 = 1; This->use_vp2 = 1;
memset(&(This->viewports.vp2), 0, sizeof(This->viewports.vp2)); memset(&(This->viewports.vp2), 0, sizeof(This->viewports.vp2));
memcpy(&(This->viewports.vp2), lpData, lpData->dwSize); memcpy(&(This->viewports.vp2), lpData, lpData->dwSize);
...@@ -744,6 +776,7 @@ IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface, ...@@ -744,6 +776,7 @@ IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface,
This->activate(This); This->activate(This);
IDirect3DViewport3_Release(current_viewport); IDirect3DViewport3_Release(current_viewport);
} }
LeaveCriticalSection(&ddraw_cs);
return D3D_OK; return D3D_OK;
} }
...@@ -822,18 +855,24 @@ IDirect3DViewportImpl_Clear2(IDirect3DViewport3 *iface, ...@@ -822,18 +855,24 @@ IDirect3DViewportImpl_Clear2(IDirect3DViewport3 *iface,
DWORD dwStencil) DWORD dwStencil)
{ {
ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface); ICOM_THIS_FROM(IDirect3DViewportImpl, IDirect3DViewport3, iface);
HRESULT hr;
TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x)\n", This, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil); TRACE("(%p)->(%08x,%p,%08x,%08x,%f,%08x)\n", This, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil);
EnterCriticalSection(&ddraw_cs);
if (This->active_device == NULL) { if (This->active_device == NULL) {
ERR(" Trying to clear a viewport not attached to a device !\n"); ERR(" Trying to clear a viewport not attached to a device !\n");
LeaveCriticalSection(&ddraw_cs);
return D3DERR_VIEWPORTHASNODEVICE; return D3DERR_VIEWPORTHASNODEVICE;
} }
return IDirect3DDevice7_Clear(ICOM_INTERFACE(This->active_device, IDirect3DDevice7), hr = IDirect3DDevice7_Clear(ICOM_INTERFACE(This->active_device, IDirect3DDevice7),
dwCount, dwCount,
lpRects, lpRects,
dwFlags, dwFlags,
dwColor, dwColor,
dvZ, dvZ,
dwStencil); dwStencil);
LeaveCriticalSection(&ddraw_cs);
return hr;
} }
/***************************************************************************** /*****************************************************************************
......
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