ddraw: Store the primary surface.

This commit is contained in:
Henri Verbeet 2011-09-15 20:01:49 +02:00 committed by Alexandre Julliard
parent 9ea45ac602
commit 5186882098
3 changed files with 16 additions and 36 deletions

View File

@ -1974,41 +1974,21 @@ static HRESULT WINAPI ddraw4_TestCooperativeLevel(IDirectDraw4 *iface)
static HRESULT WINAPI ddraw7_GetGDISurface(IDirectDraw7 *iface, IDirectDrawSurface7 **GDISurface) static HRESULT WINAPI ddraw7_GetGDISurface(IDirectDraw7 *iface, IDirectDrawSurface7 **GDISurface)
{ {
IDirectDrawImpl *This = impl_from_IDirectDraw7(iface); IDirectDrawImpl *This = impl_from_IDirectDraw7(iface);
struct wined3d_surface *wined3d_surface;
IDirectDrawSurface7 *ddsurf;
HRESULT hr;
DDSCAPS2 ddsCaps;
TRACE("iface %p, surface %p.\n", iface, GDISurface); TRACE("iface %p, surface %p.\n", iface, GDISurface);
/* Get the back buffer from the wineD3DDevice and search its
* attached surfaces for the front buffer. */
EnterCriticalSection(&ddraw_cs); EnterCriticalSection(&ddraw_cs);
hr = wined3d_device_get_back_buffer(This->wined3d_device,
0, 0, WINED3DBACKBUFFER_TYPE_MONO, &wined3d_surface); if (!(*GDISurface = &This->primary->IDirectDrawSurface7_iface))
if (FAILED(hr) || !wined3d_surface)
{ {
ERR("IWineD3DDevice::GetBackBuffer failed\n"); WARN("Primary not created yet.\n");
LeaveCriticalSection(&ddraw_cs); LeaveCriticalSection(&ddraw_cs);
return DDERR_NOTFOUND; return DDERR_NOTFOUND;
} }
IDirectDrawSurface7_AddRef(*GDISurface);
ddsurf = wined3d_surface_get_parent(wined3d_surface);
wined3d_surface_decref(wined3d_surface);
/* Find the front buffer */
ddsCaps.dwCaps = DDSCAPS_FRONTBUFFER;
hr = IDirectDrawSurface7_GetAttachedSurface(ddsurf,
&ddsCaps,
GDISurface);
if(hr != DD_OK)
{
ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr);
}
/* The AddRef is OK this time */
LeaveCriticalSection(&ddraw_cs); LeaveCriticalSection(&ddraw_cs);
return hr; return DD_OK;
} }
static HRESULT WINAPI ddraw4_GetGDISurface(IDirectDraw4 *iface, IDirectDrawSurface4 **surface) static HRESULT WINAPI ddraw4_GetGDISurface(IDirectDraw4 *iface, IDirectDrawSurface4 **surface)
@ -2803,19 +2783,11 @@ static HRESULT ddraw_create_swapchain(IDirectDrawImpl *ddraw, IDirectDrawSurface
WINED3DPRESENT_PARAMETERS presentation_parameters; WINED3DPRESENT_PARAMETERS presentation_parameters;
IDirectDrawSurfaceImpl *target = surface; IDirectDrawSurfaceImpl *target = surface;
HRESULT hr = WINED3D_OK; HRESULT hr = WINED3D_OK;
struct list *entry;
/* Search for the primary to use as render target. */ if (ddraw->primary)
LIST_FOR_EACH(entry, &ddraw->surface_list)
{ {
IDirectDrawSurfaceImpl *primary = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry); TRACE("Using primary %p.\n", ddraw->primary);
if ((primary->surface_desc.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER)) target = ddraw->primary;
== (DDSCAPS_PRIMARYSURFACE | DDSCAPS_FRONTBUFFER))
{
TRACE("Using primary %p as render target.\n", target);
target = primary;
break;
}
} }
memset(&presentation_parameters, 0, sizeof(presentation_parameters)); memset(&presentation_parameters, 0, sizeof(presentation_parameters));
@ -3251,6 +3223,9 @@ static HRESULT CreateSurface(IDirectDrawImpl *ddraw, DDSURFACEDESC2 *DDSD,
} }
} }
if (desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
ddraw->primary = object;
/* Create a WineD3DTexture if a texture was requested */ /* Create a WineD3DTexture if a texture was requested */
if (desc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE) if (desc2.ddsCaps.dwCaps & DDSCAPS_TEXTURE)
{ {

View File

@ -88,6 +88,8 @@ struct IDirectDrawImpl
struct wined3d_device *wined3d_device; struct wined3d_device *wined3d_device;
BOOL d3d_initialized; BOOL d3d_initialized;
IDirectDrawSurfaceImpl *primary;
/* DirectDraw things, which are not handled by WineD3D */ /* DirectDraw things, which are not handled by WineD3D */
DWORD cooperative_level; DWORD cooperative_level;

View File

@ -5100,6 +5100,9 @@ static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *paren
/* Reduce the ddraw surface count. */ /* Reduce the ddraw surface count. */
list_remove(&surface->surface_list_entry); list_remove(&surface->surface_list_entry);
if (surface == surface->ddraw->primary)
surface->ddraw->primary = NULL;
HeapFree(GetProcessHeap(), 0, surface); HeapFree(GetProcessHeap(), 0, surface);
} }