DDraw: Make the surface list a standard wine list
Stefan Dösinger
stefandoesinger at gmx.at
Sat Oct 14 14:57:09 CDT 2006
Updated with the suggestion from Alexandre, the render target search code does
not incorrectly rely on getting a NULL surface after LIST_FOR_EACH now.
-------------- next part --------------
From 6f63691bb56cb4a4bbfc239530b18ee0af370eff Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Sat, 14 Oct 2006 21:54:00 +0200
Subject: [PATCH] DDraw: Make the surface list a standard wine list
---
dlls/ddraw/ddraw.c | 29 ++++++++++++-----------------
dlls/ddraw/ddraw_private.h | 11 +++++------
dlls/ddraw/main.c | 2 ++
dlls/ddraw/surface.c | 10 +---------
4 files changed, 20 insertions(+), 32 deletions(-)
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index fc80517..5c5f4f1 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -1904,12 +1904,7 @@ IDirectDrawImpl_CreateNewSurface(IDirect
/* Increase the surface counter, and attach the surface */
InterlockedIncrement(&This->surfaces);
- if(This->surface_list)
- {
- This->surface_list->prev = *ppSurf;
- }
- (*ppSurf)->next = This->surface_list;
- This->surface_list = *ppSurf;
+ list_add_head(&This->surface_list, &(*ppSurf)->surface_list_entry);
/* Here we could store all created surfaces in the DirectDrawImpl structure,
* But this could also be delegated to WineDDraw, as it keeps track of all its
@@ -2375,23 +2370,20 @@ IDirectDrawImpl_CreateSurface(IDirectDra
if( (This->ImplType == SURFACE_OPENGL) && !(This->d3d_initialized) &&
desc2.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE) )
{
- IDirectDrawSurfaceImpl *target = This->surface_list;
+ IDirectDrawSurfaceImpl *target = object, *surface;
+ struct list *entry;
/* Search for the primary to use as render target */
- while(target)
+ LIST_FOR_EACH(entry, &This->surface_list)
{
- if(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
+ surface = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry);
+ if(surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{
/* found */
+ target = surface;
TRACE("Using primary %p as render target\n", target);
break;
}
- target = target->next;
- }
- /* If it's not found, use the just created DDSCAPS_3DDEVICE surface */
- if(!target)
- {
- target = object;
}
TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This, target);
@@ -2598,9 +2590,10 @@ IDirectDrawImpl_EnumSurfaces(IDirectDraw
* caps structures
*/
ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
- IDirectDrawSurfaceImpl *surf;
+ IDirectDrawSurfaceImpl *surf = NULL;
BOOL all, nomatch;
DDSURFACEDESC2 desc;
+ struct list *entry = NULL, *entry2 = NULL;
all = Flags & DDENUMSURFACES_ALL;
nomatch = Flags & DDENUMSURFACES_NOMATCH;
@@ -2610,8 +2603,10 @@ IDirectDrawImpl_EnumSurfaces(IDirectDraw
if(!Callback)
return DDERR_INVALIDPARAMS;
- for(surf = This->surface_list; surf; surf = surf->next)
+ /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
+ LIST_FOR_EACH_SAFE(entry, entry2, &This->surface_list)
{
+ surf = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry);
if (all || (nomatch != IDirectDrawImpl_DDSD_Match(DDSD, &surf->surface_desc)))
{
desc = surf->surface_desc;
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index f70da21..7181997 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -130,10 +130,6 @@ struct IDirectDrawImpl
/* The surface type to request */
WINED3DSURFTYPE ImplType;
- /* The surface list - can't relay this to WineD3D
- * because of IParent
- */
- IDirectDrawSurfaceImpl *surface_list;
/* Our private window class */
char classname[32];
@@ -145,6 +141,10 @@ struct IDirectDrawImpl
/* For the dll unload cleanup code */
struct list ddraw_list_entry;
+ /* The surface list - can't relay this to WineD3D
+ * because of IParent
+ */
+ struct list surface_list;
LONG surfaces;
};
@@ -233,8 +233,7 @@ struct IDirectDrawSurfaceImpl
IDirectDrawClipperImpl *clipper;
/* For the ddraw surface list */
- IDirectDrawSurfaceImpl *next;
- IDirectDrawSurfaceImpl *prev;
+ struct list surface_list_entry;
DWORD Handle;
};
diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c
index 8865fe5..eec98f1 100644
--- a/dlls/ddraw/main.c
+++ b/dlls/ddraw/main.c
@@ -315,6 +315,8 @@ #undef BLIT_CAPS
#undef CKEY_CAPS
#undef FX_CAPS
+ list_init(&This->surface_list);
+
EnterCriticalSection(&ddraw_list_cs);
list_add_head(&global_ddraw_list, &This->ddraw_list_entry);
LeaveCriticalSection(&ddraw_list_cs);
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 0ce28da..d7940bd 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -238,15 +238,7 @@ static void IDirectDrawSurfaceImpl_Destr
/* Reduce the ddraw surface count */
InterlockedDecrement(&This->ddraw->surfaces);
- if(This->prev)
- This->prev->next = This->next;
- else
- {
- assert(This->ddraw->surface_list == This);
- This->ddraw->surface_list = This->next;
- }
- if(This->next)
- This->next->prev = This->prev;
+ list_remove(&This->surface_list_entry);
HeapFree(GetProcessHeap(), 0, This);
}
--
1.4.1.1
More information about the wine-patches
mailing list