ddraw: Use wined3d_mutex_lock() / wined3d_mutex_unlock() for locking.

This commit is contained in:
Henri Verbeet 2011-11-13 19:52:24 +01:00 committed by Alexandre Julliard
parent 32664381fb
commit a2963b662c
11 changed files with 597 additions and 507 deletions

View File

@ -96,10 +96,10 @@ static ULONG WINAPI IDirectDrawClipperImpl_Release(IDirectDrawClipper *iface)
if (ref == 0)
{
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
wined3d_clipper_decref(This->wineD3DClipper);
wined3d_mutex_unlock();
HeapFree(GetProcessHeap(), 0, This);
LeaveCriticalSection(&ddraw_cs);
return 0;
}
else return ref;
@ -128,9 +128,10 @@ static HRESULT WINAPI IDirectDrawClipperImpl_SetHWnd(IDirectDrawClipper *iface,
TRACE("iface %p, flags %#x, window %p.\n", iface, dwFlags, hWnd);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_clipper_set_window(This->wineD3DClipper, dwFlags, hWnd);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
@ -165,9 +166,10 @@ static HRESULT WINAPI IDirectDrawClipperImpl_GetClipList(IDirectDrawClipper *ifa
TRACE("iface %p, rect %s, clip_list %p, clip_list_size %p.\n",
iface, wine_dbgstr_rect(lpRect), lpClipList, lpdwSize);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_clipper_get_clip_list(This->wineD3DClipper, lpRect, lpClipList, lpdwSize);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -193,9 +195,10 @@ static HRESULT WINAPI IDirectDrawClipperImpl_SetClipList(IDirectDrawClipper *ifa
TRACE("iface %p, clip_list %p, flags %#x.\n", iface, lprgn, dwFlag);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_clipper_set_clip_list(This->wineD3DClipper, lprgn, dwFlag);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -217,9 +220,10 @@ static HRESULT WINAPI IDirectDrawClipperImpl_GetHWnd(IDirectDrawClipper *iface,
TRACE("iface %p, window %p.\n", iface, hWndPtr);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_clipper_get_window(This->wineD3DClipper, hWndPtr);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -244,16 +248,16 @@ static HRESULT WINAPI IDirectDrawClipperImpl_Initialize(IDirectDrawClipper *ifac
TRACE("iface %p, ddraw %p, flags %#x.\n", iface, ddraw, dwFlags);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (This->initialized)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_ALREADYINITIALIZED;
}
This->initialized = TRUE;
wined3d_mutex_unlock();
LeaveCriticalSection(&ddraw_cs);
return DD_OK;
}

View File

@ -146,14 +146,14 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid,
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj);
/* Can change surface impl type */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
*obj = NULL;
if(!refiid)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -174,7 +174,7 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid,
/* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
WARN("IDirectDraw3 is not valid in ddraw.dll\n");
*obj = NULL;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return E_NOINTERFACE;
}
else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
@ -236,12 +236,13 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid,
else
{
ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return E_NOINTERFACE;
}
IUnknown_AddRef( (IUnknown *) *obj );
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return S_OK;
}
@ -479,9 +480,9 @@ static void ddraw_destroy(IDirectDrawImpl *This)
This->devicewindow = 0;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
list_remove(&This->ddraw_list_entry);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
/* This can happen more or less legitimately for ddraw 1 and 2, where
* surfaces don't keep a reference to the ddraw object. The surfaces
@ -677,7 +678,7 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
TRACE("iface %p, window %p, flags %#x.\n", iface, hwnd, cooplevel);
DDRAW_dump_cooperativelevel(cooplevel);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* Get the old window */
window = This->dest_window;
@ -688,7 +689,7 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
DDSCL_EXCLUSIVE )))
{
TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -708,12 +709,12 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
DDSCL_FULLSCREEN ) )
{
TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
hr = ddraw_set_focus_window(This, hwnd);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -722,7 +723,7 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
if( !(cooplevel & DDSCL_FULLSCREEN) || !hwnd )
{
TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN and a window\n", This);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
@ -753,7 +754,7 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
if (FAILED(hr))
{
ERR("Failed to acquire focus window, hr %#x.\n", hr);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
}
@ -773,7 +774,7 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
if (!devicewindow)
{
ERR("Failed to create window, last error %#x.\n", GetLastError());
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return E_FAIL;
}
@ -799,7 +800,8 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
/* Store the cooperative_level */
This->cooperative_level = cooplevel;
TRACE("SetCooperativeLevel retuning DD_OK\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -852,12 +854,12 @@ static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD
TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw, Width,
Height, BPP, RefreshRate, Flags);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if( !Width || !Height )
{
ERR("Width %u, Height %u, what to do?\n", Width, Height);
/* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -881,7 +883,7 @@ static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD
&& Mode.RefreshRate == RefreshRate)
{
TRACE("Skipping redundant mode setting call.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -910,7 +912,8 @@ static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD
if (ddraw->cooperative_level & DDSCL_EXCLUSIVE)
SetWindowPos(ddraw->dest_window, HWND_TOP, 0, 0, Width, Height, SWP_SHOWWINDOW | SWP_NOACTIVATE);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
@ -1081,17 +1084,18 @@ static HRESULT WINAPI ddraw7_GetCaps(IDirectDraw7 *iface, DDCAPS *DriverCaps, DD
memset(&caps, 0, sizeof(caps));
memset(&winecaps, 0, sizeof(winecaps));
caps.dwSize = sizeof(caps);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_device_get_device_caps(This->wined3d_device, &winecaps);
if (FAILED(hr))
{
WARN("IWineD3DDevice::GetDeviceCaps failed\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
hr = IDirectDraw7_GetAvailableVidMem(iface, &ddscaps, &caps.dwVidMemTotal, &caps.dwVidMemFree);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
if(FAILED(hr)) {
WARN("IDirectDraw7::GetAvailableVidMem failed\n");
return hr;
@ -1241,11 +1245,11 @@ static HRESULT WINAPI ddraw7_GetDisplayMode(IDirectDraw7 *iface, DDSURFACEDESC2
TRACE("iface %p, surface_desc %p.\n", iface, DDSD);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* This seems sane */
if (!DDSD)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -1255,7 +1259,7 @@ static HRESULT WINAPI ddraw7_GetDisplayMode(IDirectDraw7 *iface, DDSURFACEDESC2
if (FAILED(hr))
{
ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This, hr);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -1278,7 +1282,8 @@ static HRESULT WINAPI ddraw7_GetDisplayMode(IDirectDraw7 *iface, DDSURFACEDESC2
DDRAW_dump_surface_desc(DDSD);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -1529,7 +1534,7 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C
TRACE("(%p) Asked for memory with description: ", This);
DDRAW_dump_DDSCAPS2(Caps);
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* Todo: System memory vs local video memory vs non-local video memory
* The MSDN also mentions differences between texture memory and other
@ -1538,7 +1543,7 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C
if( (!total) && (!free) )
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -1552,7 +1557,8 @@ static HRESULT WINAPI ddraw7_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *C
*total = desc.video_memory;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -1783,9 +1789,9 @@ static HRESULT WINAPI ddraw7_GetScanLine(IDirectDraw7 *iface, DWORD *Scanline)
hide = TRUE;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
wined3d_device_get_display_mode(This->wined3d_device, 0, &Mode);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
/* Fake the line sweeping of the monitor */
/* FIXME: We should synchronize with a source to keep the refresh rate */
@ -1872,17 +1878,18 @@ static HRESULT WINAPI ddraw7_GetGDISurface(IDirectDraw7 *iface, IDirectDrawSurfa
TRACE("iface %p, surface %p.\n", iface, GDISurface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (!(*GDISurface = &This->primary->IDirectDrawSurface7_iface))
{
WARN("Primary not created yet.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOTFOUND;
}
IDirectDrawSurface7_AddRef(*GDISurface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -2009,14 +2016,10 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
iface, Flags, DDSD, Context, cb);
EnterCriticalSection(&ddraw_cs);
/* This looks sane */
if (!cb)
{
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
if(!(Flags & DDEDM_REFRESHRATES))
{
enum_mode_array_size = 16;
@ -2024,7 +2027,7 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
if (!enum_modes)
{
ERR("Out of memory\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
}
@ -2094,7 +2097,7 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
{
TRACE("Application asked to terminate the enumeration\n");
HeapFree(GetProcessHeap(), 0, enum_modes);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -2111,7 +2114,7 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
{
ERR("Out of memory\n");
HeapFree(GetProcessHeap(), 0, enum_modes);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
@ -2125,7 +2128,8 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
TRACE("End of enumeration\n");
HeapFree(GetProcessHeap(), 0, enum_modes);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -2749,19 +2753,20 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
TRACE(" (%p) Requesting surface desc :\n", ddraw);
DDRAW_dump_surface_desc(DDSD);
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (UnkOuter != NULL)
{
FIXME("(%p) : outer != NULL?\n", ddraw);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return CLASS_E_NOAGGREGATION; /* unchecked */
}
if (Surf == NULL)
{
FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return E_POINTER; /* unchecked */
}
@ -2790,14 +2795,14 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
ddraw);
*Surf = NULL;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOEXCLUSIVEMODE;
}
if((DDSD->ddsCaps.dwCaps & (DDSCAPS_BACKBUFFER | DDSCAPS_PRIMARYSURFACE)) == (DDSCAPS_BACKBUFFER | DDSCAPS_PRIMARYSURFACE))
{
WARN("Application wanted to create back buffer primary surface\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
@ -2805,7 +2810,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
{
/* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
WARN("Application tries to put the surface in both system and video memory\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
*Surf = NULL;
return DDERR_INVALIDCAPS;
}
@ -2817,14 +2822,14 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
!(DDSD->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP))
{
WARN("Cube map faces requested without cube map flag\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
if(DDSD->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP &&
(DDSD->ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP_ALLFACES) == 0)
{
WARN("Cube map without faces requested\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -2894,7 +2899,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
{
WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
*Surf = NULL;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -2905,7 +2910,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
if (!desc2.dwWidth || !desc2.dwHeight)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -2919,7 +2924,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
/* Mipmap count is given, should not be 0 */
if( desc2.u2.dwMipMapCount == 0 )
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
@ -2968,7 +2973,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
if (FAILED(hr))
{
WARN("ddraw_create_surface failed, hr %#x.\n", hr);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
object->is_complex_root = TRUE;
@ -3026,7 +3031,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
{
IDirectDrawSurface_Release(&object->IDirectDrawSurface_iface);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3051,7 +3056,7 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
object = object->complex_array[0];
ddraw_surface_destroy(release_surf);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
}
@ -3067,7 +3072,8 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
ddraw->tex_root = NULL;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3422,13 +3428,10 @@ static HRESULT WINAPI ddraw7_EnumSurfaces(IDirectDraw7 *iface, DWORD Flags,
all = Flags & DDENUMSURFACES_ALL;
nomatch = Flags & DDENUMSURFACES_NOMATCH;
EnterCriticalSection(&ddraw_cs);
if (!Callback)
{
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
/* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
LIST_FOR_EACH_SAFE(entry, entry2, &This->surface_list)
@ -3441,12 +3444,14 @@ static HRESULT WINAPI ddraw7_EnumSurfaces(IDirectDraw7 *iface, DWORD Flags,
IDirectDrawSurface7_AddRef(&surf->IDirectDrawSurface7_iface);
if (Callback(&surf->IDirectDrawSurface7_iface, &desc, Context) != DDENUMRET_OK)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
}
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3528,18 +3533,16 @@ DirectDrawCreateClipper(DWORD Flags,
TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
Flags, Clipper, UnkOuter);
EnterCriticalSection(&ddraw_cs);
if (UnkOuter != NULL)
{
LeaveCriticalSection(&ddraw_cs);
if (UnkOuter)
return CLASS_E_NOAGGREGATION;
}
wined3d_mutex_lock();
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(IDirectDrawClipperImpl));
if (object == NULL)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return E_OUTOFMEMORY;
}
@ -3548,13 +3551,14 @@ DirectDrawCreateClipper(DWORD Flags,
{
WARN("Failed to initialize clipper, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
TRACE("Created clipper %p.\n", object);
*Clipper = &object->IDirectDrawClipper_iface;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3633,19 +3637,16 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags,
TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
iface, Flags, ColorTable, Palette, pUnkOuter);
EnterCriticalSection(&ddraw_cs);
if(pUnkOuter != NULL)
{
WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter);
LeaveCriticalSection(&ddraw_cs);
if (pUnkOuter)
return CLASS_E_NOAGGREGATION;
}
wined3d_mutex_lock();
/* The refcount test shows that a cooplevel is required for this */
if(!This->cooperative_level)
{
WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOCOOPERATIVELEVELSET;
}
@ -3653,7 +3654,7 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags,
if(!object)
{
ERR("Out of memory when allocating memory for a palette implementation\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return E_OUTOFMEMORY;
}
@ -3662,13 +3663,14 @@ static HRESULT WINAPI ddraw7_CreatePalette(IDirectDraw7 *iface, DWORD Flags,
{
WARN("Failed to initialize palette, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
TRACE("Created palette %p.\n", object);
*Palette = &object->IDirectDrawPalette_iface;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3859,12 +3861,12 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
if (!callback)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = IDirect3DImpl_GetCaps(This->wineD3D, &device_desc1, &device_desc7);
if (hr != D3D_OK)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3877,14 +3879,14 @@ static HRESULT WINAPI d3d7_EnumDevices(IDirect3D7 *iface, LPD3DENUMDEVICESCALLBA
if (ret != DDENUMRET_OK)
{
TRACE("Application cancelled the enumeration.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
}
TRACE("End of enumeration.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -3926,12 +3928,12 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA
if (!callback)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = IDirect3DImpl_GetCaps(This->wineD3D, &device_desc1, &device_desc7);
if (hr != D3D_OK)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3971,7 +3973,7 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA
if (hr != D3DENUMRET_OK)
{
TRACE("Application cancelled the enumeration.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
}
@ -3991,13 +3993,14 @@ static HRESULT WINAPI d3d3_EnumDevices(IDirect3D3 *iface, LPD3DENUMDEVICESCALLBA
if (hr != D3DENUMRET_OK)
{
TRACE("Application cancelled the enumeration.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
TRACE("End of enumeration.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -4346,7 +4349,7 @@ static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid,
TRACE("iface %p, riid %s, surface %p, device %p.\n", iface, debugstr_guid(riid), surface, device);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
*device = NULL;
/* Fail device creation if non-opengl surfaces are used. */
@ -4357,14 +4360,14 @@ static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid,
/* We only hit this path if a default surface is set in the registry. Incorrect autodetection
* is caught in CreateSurface or QueryInterface. */
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NO3D;
}
if (This->d3ddevice)
{
FIXME("Only one Direct3D device per DirectDraw object supported.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -4372,7 +4375,7 @@ static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid,
if (!object)
{
ERR("Failed to allocate device memory.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
@ -4381,14 +4384,15 @@ static HRESULT WINAPI d3d7_CreateDevice(IDirect3D7 *iface, REFCLSID riid,
{
WARN("Failed to initialize device, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
TRACE("Created device %p.\n", object);
*device = &object->IDirect3DDevice7_iface;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -4584,7 +4588,7 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device
type = WINED3DDEVTYPE_HAL;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* We need an adapter format from somewhere to please wined3d and WGL.
* Use the current display mode. So far all cards offer the same depth
* stencil format for all modes, but if some do not and applications do
@ -4610,7 +4614,7 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device
if (hr != DDENUMRET_OK)
{
TRACE("Format enumeration cancelled by application.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
}
@ -4635,7 +4639,8 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device
TRACE("End of enumeration.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -4668,10 +4673,10 @@ static HRESULT WINAPI d3d7_EvictManagedTextures(IDirect3D7 *iface)
TRACE("iface %p!\n", iface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (This->d3d_initialized)
wined3d_device_evict_managed_resources(This->wined3d_device);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -4710,9 +4715,9 @@ HRESULT IDirect3DImpl_GetCaps(const struct wined3d *wined3d, D3DDEVICEDESC *desc
memset(&wined3d_caps, 0, sizeof(wined3d_caps));
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_get_device_caps(wined3d, 0, WINED3DDEVTYPE_HAL, &wined3d_caps);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
if (FAILED(hr))
{
WARN("Failed to get device caps, hr %#x.\n", hr);

View File

@ -52,9 +52,6 @@ typedef struct IDirect3DMaterialImpl IDirect3DMaterialImpl;
typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl;
typedef struct IDirect3DVertexBufferImpl IDirect3DVertexBufferImpl;
/* Global critical section */
extern CRITICAL_SECTION ddraw_cs DECLSPEC_HIDDEN;
extern DWORD force_refresh_rate DECLSPEC_HIDDEN;
/*****************************************************************************

File diff suppressed because it is too large Load Diff

View File

@ -224,11 +224,12 @@ static HRESULT WINAPI IDirect3DLightImpl_SetLight(IDirect3DLight *iface, D3DLIGH
light7->dvTheta = lpLight->dvTheta;
light7->dvPhi = lpLight->dvPhi;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
memcpy(&This->light, lpLight, lpLight->dwSize);
if (This->light.dwFlags & D3DLIGHT_ACTIVE)
light_update(This);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -256,9 +257,9 @@ static HRESULT WINAPI IDirect3DLightImpl_GetLight(IDirect3DLight *iface, D3DLIGH
dump_light(&This->light);
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
memcpy(lpLight, &This->light, lpLight->dwSize);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}

View File

@ -39,18 +39,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
/* The configured default surface */
WINED3DSURFTYPE DefaultSurfaceType = SURFACE_OPENGL;
/* DDraw list and critical section */
static struct list global_ddraw_list = LIST_INIT(global_ddraw_list);
static CRITICAL_SECTION_DEBUG ddraw_cs_debug =
{
0, 0, &ddraw_cs,
{ &ddraw_cs_debug.ProcessLocksList,
&ddraw_cs_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": ddraw_cs") }
};
CRITICAL_SECTION ddraw_cs = { &ddraw_cs_debug, -1, 0, 0, 0, 0 };
static HINSTANCE instance;
/* value of ForceRefreshRate */
@ -272,9 +262,9 @@ DirectDrawCreate(GUID *GUID,
TRACE("driver_guid %s, ddraw %p, outer_unknown %p.\n",
debugstr_guid(GUID), DD, UnkOuter);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = DDRAW_Create(GUID, (void **) DD, UnkOuter, &IID_IDirectDraw);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
if (SUCCEEDED(hr))
{
@ -309,9 +299,9 @@ DirectDrawCreateEx(GUID *guid,
if (!IsEqualGUID(iid, &IID_IDirectDraw7))
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = DDRAW_Create(guid, dd, UnkOuter, iid);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
if (SUCCEEDED(hr))
{
@ -466,9 +456,10 @@ CF_CreateDirectDraw(IUnknown* UnkOuter, REFIID iid,
TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter, debugstr_guid(iid), obj);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = DDRAW_Create(NULL, obj, UnkOuter, iid);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -495,18 +486,19 @@ CF_CreateDirectDrawClipper(IUnknown* UnkOuter, REFIID riid,
TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter, debugstr_guid(riid), obj);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = DirectDrawCreateClipper(0, &Clip, UnkOuter);
if (hr != DD_OK)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
hr = IDirectDrawClipper_QueryInterface(Clip, riid, obj);
IDirectDrawClipper_Release(Clip);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}

View File

@ -142,9 +142,9 @@ static ULONG WINAPI IDirect3DMaterialImpl_Release(IDirect3DMaterial3 *iface)
{
if(This->Handle)
{
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
ddraw_free_handle(&This->ddraw->d3ddevice->handle_table, This->Handle - 1, DDRAW_HANDLE_MATERIAL);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
}
HeapFree(GetProcessHeap(), 0, This);
@ -236,10 +236,10 @@ static HRESULT WINAPI IDirect3DMaterialImpl_SetMaterial(IDirect3DMaterial3 *ifac
dump_material(lpMat);
/* Stores the material */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
memset(&This->mat, 0, sizeof(This->mat));
memcpy(&This->mat, lpMat, lpMat->dwSize);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -271,10 +271,10 @@ static HRESULT WINAPI IDirect3DMaterialImpl_GetMaterial(IDirect3DMaterial3 *ifac
}
/* Copies the material structure */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
dwSize = lpMat->dwSize;
memcpy(lpMat, &This->mat, dwSize);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -302,7 +302,7 @@ static HRESULT WINAPI IDirect3DMaterialImpl_GetHandle(IDirect3DMaterial3 *iface,
TRACE("iface %p, device %p, handle %p.\n", iface, device, handle);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
This->active_device = device_impl;
if(!This->Handle)
{
@ -310,7 +310,7 @@ static HRESULT WINAPI IDirect3DMaterialImpl_GetHandle(IDirect3DMaterial3 *iface,
if (h == DDRAW_INVALID_HANDLE)
{
ERR("Failed to allocate a material handle.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS; /* Unchecked */
}
@ -318,7 +318,7 @@ static HRESULT WINAPI IDirect3DMaterialImpl_GetHandle(IDirect3DMaterial3 *iface,
}
*handle = This->Handle;
TRACE(" returning handle %08x.\n", *handle);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}

View File

@ -97,13 +97,14 @@ IDirectDrawPaletteImpl_Release(IDirectDrawPalette *iface)
if (ref == 0)
{
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
wined3d_palette_decref(This->wineD3DPalette);
if(This->ifaceToRelease)
{
IUnknown_Release(This->ifaceToRelease);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
HeapFree(GetProcessHeap(), 0, This);
}
@ -159,9 +160,9 @@ IDirectDrawPaletteImpl_GetCaps(IDirectDrawPalette *iface,
TRACE("iface %p, caps %p.\n", iface, Caps);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
*Caps = wined3d_palette_get_flags(This->wineD3DPalette);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -200,9 +201,10 @@ IDirectDrawPaletteImpl_SetEntries(IDirectDrawPalette *iface,
if(!PalEnt)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_palette_set_entries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -239,9 +241,10 @@ IDirectDrawPaletteImpl_GetEntries(IDirectDrawPalette *iface,
if(!PalEnt)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_palette_get_entries(This->wineD3DPalette, Flags, Start, Count, PalEnt);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}

View File

@ -296,12 +296,12 @@ static void ddraw_surface_add_iface(IDirectDrawSurfaceImpl *This)
if (iface_count == 1)
{
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (This->wined3d_surface)
wined3d_surface_incref(This->wined3d_surface);
if (This->wined3d_texture)
wined3d_texture_incref(This->wined3d_texture);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
}
}
@ -511,18 +511,18 @@ ULONG ddraw_surface_release_iface(IDirectDrawSurfaceImpl *This)
if (iface_count == 0)
{
/* Complex attached surfaces are destroyed implicitly when the root is released */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if(!This->is_complex_root)
{
WARN("(%p) Attempt to destroy a surface that is not a complex root\n", This);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return iface_count;
}
if (This->wined3d_texture) /* If it's a texture, destroy the wined3d texture. */
wined3d_texture_decref(This->wined3d_texture);
else
ddraw_surface_cleanup(This);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
}
return iface_count;
@ -700,7 +700,7 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa
TRACE("iface %p, caps %p, attachment %p.\n", iface, Caps, Surface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if(This->version < 7)
{
@ -744,7 +744,8 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa
TRACE("(%p): mipmapcount=%d\n", This, surf->mipmap_level);
*Surface = &surf->IDirectDrawSurface7_iface;
ddraw_surface7_AddRef(*Surface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
}
@ -769,13 +770,14 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa
TRACE("(%p): Returning surface %p\n", This, surf);
*Surface = &surf->IDirectDrawSurface7_iface;
ddraw_surface7_AddRef(*Surface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
}
TRACE("(%p) Didn't find a valid surface\n", This);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
*Surface = NULL;
return DDERR_NOTFOUND;
@ -926,7 +928,7 @@ static HRESULT surface_lock(IDirectDrawSurfaceImpl *This,
This, wine_dbgstr_rect(Rect), DDSD, Flags, h);
/* This->surface_desc.dwWidth and dwHeight are changeable, thus lock */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* Should I check for the handle to be NULL?
*
@ -947,7 +949,7 @@ static HRESULT surface_lock(IDirectDrawSurfaceImpl *This,
|| (Rect->bottom > This->surface_desc.dwHeight))
{
WARN("Trying to lock an invalid rectangle, returning DDERR_INVALIDPARAMS\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
@ -958,7 +960,7 @@ static HRESULT surface_lock(IDirectDrawSurfaceImpl *This,
hr = wined3d_surface_map(This->wined3d_surface, &LockedRect, Rect, Flags);
if (FAILED(hr))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
/* D3D8 and D3D9 return the general D3DERR_INVALIDCALL error, but ddraw has a more
@ -992,7 +994,8 @@ static HRESULT surface_lock(IDirectDrawSurfaceImpl *This,
TRACE("locked surface returning description :\n");
if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -1125,7 +1128,7 @@ static HRESULT WINAPI ddraw_surface7_Unlock(IDirectDrawSurface7 *iface, RECT *pR
TRACE("iface %p, rect %s.\n", iface, wine_dbgstr_rect(pRect));
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_unmap(This->wined3d_surface);
if (SUCCEEDED(hr))
{
@ -1133,7 +1136,8 @@ static HRESULT WINAPI ddraw_surface7_Unlock(IDirectDrawSurface7 *iface, RECT *pR
hr = ddraw_surface_update_frontbuffer(This, &This->ddraw->primary_lock, FALSE);
This->surface_desc.lpSurface = NULL;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -1206,7 +1210,7 @@ static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDra
if( !(This->surface_desc.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_OVERLAY)) )
return DDERR_INVALIDOBJECT; /* Unchecked */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* WineD3D doesn't keep track of attached surface, so find the target */
if(!Override)
@ -1219,7 +1223,7 @@ static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDra
if(hr != DD_OK)
{
ERR("Can't find a flip target\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOTFLIPPABLE; /* Unchecked */
}
Override = impl_from_IDirectDrawSurface7(Override7);
@ -1232,7 +1236,8 @@ static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDra
if (SUCCEEDED(hr) && This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
hr = ddraw_surface_update_frontbuffer(This, NULL, FALSE);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -1316,11 +1321,11 @@ static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestR
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if(Flags & DDBLT_KEYSRC && (!Src || !(Src->surface_desc.dwFlags & DDSD_CKSRCBLT))) {
WARN("DDBLT_KEYDEST blit without color key in surface, returning DDERR_INVALIDPARAMS\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -1336,7 +1341,7 @@ static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestR
if (SUCCEEDED(hr) && (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER))
hr = ddraw_surface_update_frontbuffer(This, DestRect, FALSE);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
@ -1444,7 +1449,7 @@ static HRESULT ddraw_surface_attach_surface(IDirectDrawSurfaceImpl *This, IDirec
if(Surf == This)
return DDERR_CANNOTATTACHSURFACE; /* unchecked */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* Check if the surface is already attached somewhere */
if (Surf->next_attached || Surf->first_attached != Surf)
@ -1455,7 +1460,7 @@ static HRESULT ddraw_surface_attach_surface(IDirectDrawSurfaceImpl *This, IDirec
WARN("Surface %p is already attached somewhere. next_attached %p, first_attached %p.\n",
Surf, Surf->next_attached, Surf->first_attached);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_SURFACEALREADYATTACHED;
}
@ -1470,7 +1475,8 @@ static HRESULT ddraw_surface_attach_surface(IDirectDrawSurfaceImpl *This, IDirec
IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -1628,17 +1634,17 @@ static HRESULT ddraw_surface_delete_attached_surface(IDirectDrawSurfaceImpl *Thi
TRACE("surface %p, attachment %p, detach_iface %p.\n", This, Surf, detach_iface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (!Surf || (Surf->first_attached != This) || (Surf == This) )
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_CANNOTDETACHSURFACE;
}
if (Surf->attached_iface != detach_iface)
{
WARN("Surf->attach_iface %p != detach_iface %p.\n", Surf->attached_iface, detach_iface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_SURFACENOTATTACHED;
}
@ -1671,7 +1677,7 @@ static HRESULT ddraw_surface_delete_attached_surface(IDirectDrawSurfaceImpl *Thi
{
IDirect3DDeviceImpl_UpdateDepthStencil(This->ddraw->d3ddevice);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
/* Set attached_iface to NULL before releasing it, the surface may go
* away. */
@ -1811,12 +1817,12 @@ static HRESULT WINAPI ddraw_surface7_GetDC(IDirectDrawSurface7 *iface, HDC *hdc)
if(!hdc)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
hr = ddraw_surface_update_frontbuffer(This, NULL, TRUE);
if (SUCCEEDED(hr))
hr = wined3d_surface_getdc(This->wined3d_surface, hdc);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
/* Some, but not all errors set *hdc to NULL. E.g. DCALREADYCREATED does not
@ -1882,11 +1888,12 @@ static HRESULT WINAPI ddraw_surface7_ReleaseDC(IDirectDrawSurface7 *iface, HDC h
TRACE("iface %p, dc %p.\n", iface, hdc);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_releasedc(This->wined3d_surface, hdc);
if (SUCCEEDED(hr) && (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER))
hr = ddraw_surface_update_frontbuffer(This, NULL, FALSE);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -2021,9 +2028,10 @@ static HRESULT WINAPI ddraw_surface7_SetPriority(IDirectDrawSurface7 *iface, DWO
TRACE("iface %p, priority %u.\n", iface, Priority);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_set_priority(This->wined3d_surface, Priority);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -2052,9 +2060,10 @@ static HRESULT WINAPI ddraw_surface7_GetPriority(IDirectDrawSurface7 *iface, DWO
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
*Priority = wined3d_surface_get_priority(This->wined3d_surface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -2085,10 +2094,11 @@ static HRESULT WINAPI ddraw_surface7_SetPrivateData(IDirectDrawSurface7 *iface,
TRACE("iface %p, tag %s, data %p, data_size %u, flags %#x.\n",
iface, debugstr_guid(tag), Data, Size, Flags);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
resource = wined3d_surface_get_resource(This->wined3d_surface);
hr = wined3d_resource_set_private_data(resource, tag, Data, Size, Flags);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
@ -2134,10 +2144,11 @@ static HRESULT WINAPI ddraw_surface7_GetPrivateData(IDirectDrawSurface7 *iface,
if(!Data)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
resource = wined3d_surface_get_resource(This->wined3d_surface);
hr = wined3d_resource_get_private_data(resource, tag, Data, Size);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -2171,10 +2182,11 @@ static HRESULT WINAPI ddraw_surface7_FreePrivateData(IDirectDrawSurface7 *iface,
TRACE("iface %p, tag %s.\n", iface, debugstr_guid(tag));
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
resource = wined3d_surface_get_resource(This->wined3d_surface);
hr = wined3d_resource_free_private_data(resource, tag);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -2353,7 +2365,8 @@ static HRESULT WINAPI ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7 *i
if(!cb)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
{
surf = This->complex_array[i];
@ -2364,7 +2377,7 @@ static HRESULT WINAPI ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7 *i
/* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
if (cb(&surf->IDirectDrawSurface7_iface, &desc, context) == DDENUMRET_CANCEL)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
}
@ -2376,14 +2389,15 @@ static HRESULT WINAPI ddraw_surface7_EnumAttachedSurfaces(IDirectDrawSurface7 *i
/* check: != DDENUMRET_OK or == DDENUMRET_CANCEL? */
if (cb(&surf->IDirectDrawSurface7_iface, &desc, context) == DDENUMRET_CANCEL)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
}
TRACE(" end of enumeration.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -2584,9 +2598,9 @@ static HRESULT WINAPI ddraw_surface7_GetBltStatus(IDirectDrawSurface7 *iface, DW
TRACE("iface %p, flags %#x.\n", iface, Flags);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_get_blt_status(This->wined3d_surface, Flags);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
@ -2649,14 +2663,14 @@ static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWO
if(!CKey)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
switch (Flags)
{
case DDCKEY_DESTBLT:
if (!(This->surface_desc.dwFlags & DDSD_CKDESTBLT))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOCOLORKEY;
}
*CKey = This->surface_desc.ddckCKDestBlt;
@ -2665,7 +2679,7 @@ static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWO
case DDCKEY_DESTOVERLAY:
if (!(This->surface_desc.dwFlags & DDSD_CKDESTOVERLAY))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOCOLORKEY;
}
*CKey = This->surface_desc.u3.ddckCKDestOverlay;
@ -2674,7 +2688,7 @@ static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWO
case DDCKEY_SRCBLT:
if (!(This->surface_desc.dwFlags & DDSD_CKSRCBLT))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOCOLORKEY;
}
*CKey = This->surface_desc.ddckCKSrcBlt;
@ -2683,18 +2697,19 @@ static HRESULT WINAPI ddraw_surface7_GetColorKey(IDirectDrawSurface7 *iface, DWO
case DDCKEY_SRCOVERLAY:
if (!(This->surface_desc.dwFlags & DDSD_CKSRCOVERLAY))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOCOLORKEY;
}
*CKey = This->surface_desc.ddckCKSrcOverlay;
break;
default:
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -2749,9 +2764,10 @@ static HRESULT WINAPI ddraw_surface7_GetFlipStatus(IDirectDrawSurface7 *iface, D
TRACE("iface %p, flags %#x.\n", iface, Flags);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_get_flip_status(This->wined3d_surface, Flags);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
@ -2810,9 +2826,10 @@ static HRESULT WINAPI ddraw_surface7_GetOverlayPosition(IDirectDrawSurface7 *ifa
TRACE("iface %p, x %p, y %p.\n", iface, X, Y);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_get_overlay_position(This->wined3d_surface, X, Y);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -2872,9 +2889,9 @@ static HRESULT WINAPI ddraw_surface7_GetPixelFormat(IDirectDrawSurface7 *iface,
if(!PixelFormat)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
DD_STRUCT_COPY_BYSIZE(PixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -2940,12 +2957,12 @@ static HRESULT WINAPI ddraw_surface7_GetSurfaceDesc(IDirectDrawSurface7 *iface,
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
DD_STRUCT_COPY_BYSIZE(DDSD,&This->surface_desc);
TRACE("Returning surface desc:\n");
if (TRACE_ON(ddraw)) DDRAW_dump_surface_desc(DDSD);
wined3d_mutex_unlock();
LeaveCriticalSection(&ddraw_cs);
return DD_OK;
}
@ -2971,7 +2988,7 @@ static HRESULT WINAPI ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3 *iface,
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
DDSD2_to_DDSD(&This->surface_desc, surface_desc);
TRACE("Returning surface desc:\n");
if (TRACE_ON(ddraw))
@ -2979,8 +2996,8 @@ static HRESULT WINAPI ddraw_surface3_GetSurfaceDesc(IDirectDrawSurface3 *iface,
/* DDRAW_dump_surface_desc handles the smaller size */
DDRAW_dump_surface_desc((DDSURFACEDESC2 *)surface_desc);
}
wined3d_mutex_unlock();
LeaveCriticalSection(&ddraw_cs);
return DD_OK;
}
@ -3105,9 +3122,10 @@ static HRESULT WINAPI ddraw_surface7_IsLost(IDirectDrawSurface7 *iface)
TRACE("iface %p.\n", iface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_is_lost(This->wined3d_surface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
/* D3D8 and 9 loose full devices, thus there's only a DEVICELOST error.
@ -3168,9 +3186,10 @@ static HRESULT WINAPI ddraw_surface7_Restore(IDirectDrawSurface7 *iface)
TRACE("iface %p.\n", iface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_restore(This->wined3d_surface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3225,9 +3244,10 @@ static HRESULT WINAPI ddraw_surface7_SetOverlayPosition(IDirectDrawSurface7 *ifa
TRACE("iface %p, x %d, y %d.\n", iface, X, Y);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_set_overlay_position(This->wined3d_surface, X, Y);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3288,10 +3308,11 @@ static HRESULT WINAPI ddraw_surface7_UpdateOverlay(IDirectDrawSurface7 *iface, R
TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n",
iface, wine_dbgstr_rect(SrcRect), DstSurface, wine_dbgstr_rect(DstRect), Flags, FX);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_update_overlay(This->wined3d_surface, SrcRect,
Dst ? Dst->wined3d_surface : NULL, DstRect, Flags, (WINEDDOVERLAYFX *)FX);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr) {
case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
case WINEDDERR_NOTAOVERLAYSURFACE: return DDERR_NOTAOVERLAYSURFACE;
@ -3421,10 +3442,11 @@ static HRESULT WINAPI ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7 *if
TRACE("iface %p, flags %#x, reference %p.\n", iface, Flags, DDSRef);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_surface_update_overlay_z_order(This->wined3d_surface,
Flags, Ref ? Ref->wined3d_surface : NULL);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3551,7 +3573,7 @@ static HRESULT WINAPI ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7 *
TRACE("iface %p.\n", iface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* A uniqueness value of 0 is apparently special.
* This needs to be checked.
* TODO: Write tests for this code and check if the volatile, interlocked stuff is really needed
@ -3570,7 +3592,8 @@ static HRESULT WINAPI ddraw_surface7_ChangeUniquenessValue(IDirectDrawSurface7 *
break;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3588,9 +3611,10 @@ static HRESULT WINAPI ddraw_surface7_GetUniquenessValue(IDirectDrawSurface7 *ifa
TRACE("iface %p, value %p.\n", iface, pValue);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
*pValue = This->uniqueness_value;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3622,22 +3646,23 @@ static HRESULT WINAPI ddraw_surface7_SetLOD(IDirectDrawSurface7 *iface, DWORD Ma
TRACE("iface %p, lod %u.\n", iface, MaxLOD);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDOBJECT;
}
if (!This->wined3d_texture)
{
ERR("(%p) The DirectDraw texture has no WineD3DTexture!\n", This);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDOBJECT;
}
hr = wined3d_texture_set_lod(This->wined3d_texture, MaxLOD);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -3664,15 +3689,16 @@ static HRESULT WINAPI ddraw_surface7_GetLOD(IDirectDrawSurface7 *iface, DWORD *M
if(!MaxLOD)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (!(This->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDOBJECT;
}
*MaxLOD = wined3d_texture_get_lod(This->wined3d_texture);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3740,7 +3766,7 @@ static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD d
if (trans & DDBLTFAST_DONOTWAIT)
flags |= WINEDDBLT_DONOTWAIT;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (src->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
hr = ddraw_surface_update_frontbuffer(src, rsrc, TRUE);
if (SUCCEEDED(hr))
@ -3748,7 +3774,8 @@ static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD d
src->wined3d_surface, rsrc, flags, NULL, WINED3DTEXF_POINT);
if (SUCCEEDED(hr) && (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER))
hr = ddraw_surface_update_frontbuffer(This, &dst_rect, FALSE);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(hr)
{
case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
@ -3827,21 +3854,19 @@ static HRESULT WINAPI ddraw_surface7_GetClipper(IDirectDrawSurface7 *iface, IDir
TRACE("iface %p, clipper %p.\n", iface, Clipper);
if (!Clipper)
{
LeaveCriticalSection(&ddraw_cs);
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if(This->clipper == NULL)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOCLIPPERATTACHED;
}
*Clipper = (IDirectDrawClipper *)This->clipper;
IDirectDrawClipper_AddRef(*Clipper);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3900,10 +3925,10 @@ static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface,
TRACE("iface %p, clipper %p.\n", iface, iclipper);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (clipper == This->clipper)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -3936,7 +3961,8 @@ static HRESULT WINAPI ddraw_surface7_SetClipper(IDirectDrawSurface7 *iface,
}
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -4007,7 +4033,7 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (DDSD->dwFlags & DDSD_PIXELFORMAT)
{
newFormat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
@ -4015,7 +4041,7 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
if(newFormat == WINED3DFMT_UNKNOWN)
{
ERR("Requested to set an unknown pixelformat\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
if(newFormat != PixelFormat_DD2WineD3D(&This->surface_desc.u4.ddpfPixelFormat) )
@ -4023,7 +4049,7 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
hr = wined3d_surface_set_format(This->wined3d_surface, newFormat);
if (FAILED(hr))
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
}
@ -4057,7 +4083,7 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
switch(hr)
{
case WINED3DERR_INVALIDCALL:
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
default:
break; /* Go on */
@ -4067,7 +4093,8 @@ static HRESULT WINAPI ddraw_surface7_SetSurfaceDesc(IDirectDrawSurface7 *iface,
This->surface_desc = *DDSD;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -4118,7 +4145,7 @@ static HRESULT WINAPI ddraw_surface7_GetPalette(IDirectDrawSurface7 *iface, IDir
if(!Pal)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
wined3d_palette = wined3d_surface_get_palette(This->wined3d_surface);
if (wined3d_palette)
{
@ -4131,7 +4158,8 @@ static HRESULT WINAPI ddraw_surface7_GetPalette(IDirectDrawSurface7 *iface, IDir
hr = DDERR_NOPALETTEATTACHED;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -4227,7 +4255,7 @@ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWO
TRACE("iface %p, flags %#x, color_key %p.\n", iface, Flags, CKey);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (CKey)
{
FixedCKey = *CKey;
@ -4258,7 +4286,7 @@ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWO
break;
default:
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
@ -4283,13 +4311,14 @@ static HRESULT WINAPI ddraw_surface7_SetColorKey(IDirectDrawSurface7 *iface, DWO
break;
default:
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
ctx.ret = wined3d_surface_set_color_key(This->wined3d_surface, Flags, ctx.CKey);
ddraw_surface7_EnumAttachedSurfaces(iface, &ctx, SetColorKeyEnum);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
switch(ctx.ret)
{
case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
@ -4362,11 +4391,11 @@ static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDir
}
/* Find the old palette */
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = IDirectDrawSurface_GetPalette(iface, &oldPal);
if(hr != DD_OK && hr != DDERR_NOPALETTEATTACHED)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
if(oldPal) IDirectDrawPalette_Release(oldPal); /* For the GetPalette */
@ -4413,7 +4442,8 @@ static HRESULT WINAPI ddraw_surface7_SetPalette(IDirectDrawSurface7 *iface, IDir
}
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -4476,7 +4506,7 @@ static HRESULT WINAPI ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl *
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{
/* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP. */
@ -4486,7 +4516,7 @@ static HRESULT WINAPI ddraw_gamma_control_GetGammaRamp(IDirectDrawGammaControl *
{
ERR("Not implemented for non-primary surfaces.\n");
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -4518,7 +4548,7 @@ static HRESULT WINAPI ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl *
return DDERR_INVALIDPARAMS;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{
/* Note: DDGAMMARAMP is compatible with WINED3DGAMMARAMP */
@ -4528,7 +4558,7 @@ static HRESULT WINAPI ddraw_gamma_control_SetGammaRamp(IDirectDrawGammaControl *
{
ERR("Not implemented for non-primary surfaces.\n");
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -4601,7 +4631,7 @@ static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface,
TRACE("iface %p, device %p, handle %p.\n", iface, device, handle);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (!surface->Handle)
{
@ -4609,7 +4639,7 @@ static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface,
if (h == DDRAW_INVALID_HANDLE)
{
ERR("Failed to allocate a texture handle.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
@ -4619,7 +4649,7 @@ static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface,
TRACE("Returning handle %08x.\n", surface->Handle);
*handle = surface->Handle;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -4690,7 +4720,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu
return D3D_OK;
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (((src_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
!= (dst_surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_MIPMAP))
@ -4726,7 +4756,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu
if (!dst_pal)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_NOPALETTEATTACHED;
}
IDirectDrawPalette_GetEntries(src_pal, 0, 0, 256, palent);
@ -4741,7 +4771,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu
{
/* Should also check for same pixel format, u1.lPitch, ... */
ERR("Error in surface sizes.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3DERR_TEXTURE_LOAD_FAILED;
}
else
@ -4763,7 +4793,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu
if (FAILED(hr))
{
ERR("Failed to lock source surface, hr %#x.\n", hr);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3DERR_TEXTURE_LOAD_FAILED;
}
@ -4772,7 +4802,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu
{
ERR("Failed to lock destination surface, hr %#x.\n", hr);
wined3d_surface_unmap(src_surface->wined3d_surface);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3DERR_TEXTURE_LOAD_FAILED;
}
@ -4803,7 +4833,7 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu
}
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}

View File

@ -150,11 +150,11 @@ static ULONG WINAPI IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *if
struct wined3d_buffer *curVB = NULL;
UINT offset, stride;
EnterCriticalSection(&ddraw_cs);
/* D3D7 Vertex buffers don't stay bound in the device, they are passed
* as a parameter to drawPrimitiveVB. DrawPrimitiveVB sets them as the
* stream source in wined3d, and they should get unset there before
* they are destroyed. */
wined3d_mutex_lock();
wined3d_device_get_stream_source(This->ddraw->wined3d_device,
0, &curVB, &offset, &stride);
if (curVB == This->wineD3DVertexBuffer)
@ -164,7 +164,8 @@ static ULONG WINAPI IDirect3DVertexBufferImpl_Release(IDirect3DVertexBuffer7 *if
wined3d_vertex_declaration_decref(This->wineD3DVertexDeclaration);
wined3d_buffer_decref(This->wineD3DVertexBuffer);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
HeapFree(GetProcessHeap(), 0, This);
return 0;
@ -223,7 +224,7 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *ifa
if(Flags & DDLOCK_NOOVERWRITE) wined3d_flags |= WINED3DLOCK_NOOVERWRITE;
if(Flags & DDLOCK_DISCARDCONTENTS) wined3d_flags |= WINED3DLOCK_DISCARD;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if(Size)
{
/* Get the size, for returning it, and for locking */
@ -233,7 +234,8 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_Lock(IDirect3DVertexBuffer7 *ifa
}
hr = wined3d_buffer_map(This->wineD3DVertexBuffer, 0, 0, (BYTE **)Data, wined3d_flags);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -262,9 +264,9 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_Unlock(IDirect3DVertexBuffer7 *i
TRACE("iface %p.\n", iface);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
wined3d_buffer_unmap(This->wineD3DVertexBuffer);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -326,7 +328,8 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_ProcessVertices(IDirect3DVertexB
*/
if( !(VertexOp & D3DVOP_TRANSFORM) ) return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
/* WineD3D doesn't know d3d7 vertex operation, it uses
* render states instead. Set the render states according to
* the vertex ops
@ -345,7 +348,9 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_ProcessVertices(IDirect3DVertexB
/* Restore the states if needed */
if (doClip != oldClip)
wined3d_device_set_render_state(device_impl->wined3d_device, WINED3DRS_CLIPPING, oldClip);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -389,10 +394,10 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_GetVertexBufferDesc(IDirect3DVer
if(!Desc) return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
wined3d_resource = wined3d_buffer_get_resource(This->wineD3DVertexBuffer);
wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
/* Now fill the Desc structure */
Desc->dwCaps = This->Caps;
@ -443,9 +448,9 @@ static HRESULT WINAPI IDirect3DVertexBufferImpl_Optimize(IDirect3DVertexBuffer7
/* We could forward this call to WineD3D and take advantage
* of it once we use OpenGL vertex buffers
*/
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
This->Caps |= D3DVBCAPS_OPTIMIZED;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -562,7 +567,7 @@ HRESULT d3d_vertex_buffer_create(IDirect3DVertexBufferImpl **vertex_buf, IDirect
usage = desc->dwCaps & D3DVBCAPS_WRITEONLY ? WINED3DUSAGE_WRITEONLY : 0;
usage |= WINED3DUSAGE_STATICDECL;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
hr = wined3d_buffer_create_vb(ddraw->wined3d_device,
get_flexible_vertex_size(desc->dwFVF) * desc->dwNumVertices,
@ -587,7 +592,7 @@ HRESULT d3d_vertex_buffer_create(IDirect3DVertexBufferImpl **vertex_buf, IDirect
wined3d_vertex_declaration_incref(buffer->wineD3DVertexDeclaration);
end:
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
if (hr == D3D_OK)
*vertex_buf = buffer;
else

View File

@ -245,7 +245,8 @@ IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface,
TRACE("iface %p, data %p.\n", iface, lpData);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
dwSize = lpData->dwSize;
memset(lpData, 0, dwSize);
if (!This->use_vp2)
@ -271,7 +272,8 @@ IDirect3DViewportImpl_GetViewport(IDirect3DViewport3 *iface,
TRACE(" returning D3DVIEWPORT :\n");
_dump_D3DVIEWPORT(lpData);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -304,7 +306,8 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface,
_dump_D3DVIEWPORT(lpData);
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
This->use_vp2 = 0;
memset(&(This->viewports.vp1), 0, sizeof(This->viewports.vp1));
memcpy(&(This->viewports.vp1), lpData, lpData->dwSize);
@ -324,7 +327,8 @@ IDirect3DViewportImpl_SetViewport(IDirect3DViewport3 *iface,
IDirect3DViewport3_Release(current_viewport);
}
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DD_OK;
}
@ -391,7 +395,7 @@ IDirect3DViewportImpl_TransformVertices(IDirect3DViewport3 *iface,
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
wined3d_device_get_transform(This->active_device->wined3d_device,
D3DTRANSFORMSTATE_VIEW, (WINED3DMATRIX *)&view_mat);
wined3d_device_get_transform(This->active_device->wined3d_device,
@ -476,7 +480,7 @@ IDirect3DViewportImpl_TransformVertices(IDirect3DViewport3 *iface,
{
*lpOffScreen = 0;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
TRACE("All done\n");
return DD_OK;
@ -525,13 +529,13 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface,
TRACE("iface %p, material %#x.\n", iface, hMat);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (!hMat)
{
This->background = NULL;
TRACE("Setting background to NULL\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -539,7 +543,7 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface,
if (!m)
{
WARN("Invalid material handle.\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -548,7 +552,8 @@ IDirect3DViewportImpl_SetBackground(IDirect3DViewport3 *iface,
m->mat.u.diffuse.u3.b, m->mat.u.diffuse.u4.a);
This->background = m;
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -574,7 +579,7 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface,
TRACE("iface %p, material %p, valid %p.\n", iface, lphMat, lpValid);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if(lpValid)
{
*lpValid = This->background != NULL;
@ -590,7 +595,7 @@ IDirect3DViewportImpl_GetBackground(IDirect3DViewport3 *iface,
*lphMat = 0;
}
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -674,7 +679,8 @@ static HRESULT WINAPI IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface,
}
d3d_device3 = &This->active_device->IDirect3DDevice3_iface;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (dwFlags & D3DCLEAR_TARGET) {
if (This->background == NULL) {
ERR(" Trying to clear the color buffer without background material !\n");
@ -702,7 +708,8 @@ static HRESULT WINAPI IDirect3DViewportImpl_Clear(IDirect3DViewport3 *iface,
IDirect3DViewport3_Release(current_viewport);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -730,10 +737,11 @@ static HRESULT WINAPI IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface,
TRACE("iface %p, light %p.\n", iface, lpDirect3DLight);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (This->num_lights >= 8)
{
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -758,7 +766,8 @@ static HRESULT WINAPI IDirect3DViewportImpl_AddLight(IDirect3DViewport3 *iface,
if (This->active_device)
light_activate(lpDirect3DLightImpl);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -783,12 +792,12 @@ static HRESULT WINAPI IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *ifac
TRACE("iface %p, light %p.\n", iface, lpDirect3DLight);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (l->active_viewport != This)
{
WARN("Light %p active viewport is %p.\n", l, l->active_viewport);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
@ -799,7 +808,7 @@ static HRESULT WINAPI IDirect3DViewportImpl_DeleteLight(IDirect3DViewport3 *ifac
--This->num_lights;
This->map_lights &= ~(1 << l->dwLightIndex);
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -831,7 +840,7 @@ static HRESULT WINAPI IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface,
if (!lplpDirect3DLight)
return DDERR_INVALIDPARAMS;
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
switch (dwFlags)
{
@ -872,7 +881,7 @@ static HRESULT WINAPI IDirect3DViewportImpl_NextLight(IDirect3DViewport3 *iface,
hr = DDERR_INVALIDPARAMS;
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}
@ -906,7 +915,7 @@ IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface,
TRACE("iface %p, data %p.\n", iface, lpData);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
dwSize = lpData->dwSize;
memset(lpData, 0, dwSize);
if (This->use_vp2)
@ -933,7 +942,8 @@ IDirect3DViewportImpl_GetViewport2(IDirect3DViewport3 *iface,
_dump_D3DVIEWPORT2(lpData);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -964,7 +974,8 @@ IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface,
_dump_D3DVIEWPORT2(lpData);
}
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
This->use_vp2 = 1;
memset(&(This->viewports.vp2), 0, sizeof(This->viewports.vp2));
memcpy(&(This->viewports.vp2), lpData, lpData->dwSize);
@ -978,7 +989,8 @@ IDirect3DViewportImpl_SetViewport2(IDirect3DViewport3 *iface,
IDirect3DViewport3_Release(current_viewport);
}
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3D_OK;
}
@ -1064,10 +1076,11 @@ IDirect3DViewportImpl_Clear2(IDirect3DViewport3 *iface,
TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, depth %.8e, stencil %u.\n",
iface, dwCount, lpRects, dwFlags, dwColor, dvZ, dwStencil);
EnterCriticalSection(&ddraw_cs);
wined3d_mutex_lock();
if (This->active_device == NULL) {
ERR(" Trying to clear a viewport not attached to a device !\n");
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return D3DERR_VIEWPORTHASNODEVICE;
}
d3d_device3 = &This->active_device->IDirect3DDevice3_iface;
@ -1083,7 +1096,9 @@ IDirect3DViewportImpl_Clear2(IDirect3DViewport3 *iface,
viewport_activate(vp, TRUE);
IDirect3DViewport3_Release(current_viewport);
}
LeaveCriticalSection(&ddraw_cs);
wined3d_mutex_unlock();
return hr;
}