ddraw: Introduce a function to convert a DDSURFACEDESC to a DDSURFACEDESC2.

This commit is contained in:
Stefan Dösinger 2011-08-26 14:22:40 +02:00 committed by Alexandre Julliard
parent 167b65ca5e
commit 76fecde8fb
4 changed files with 79 additions and 14 deletions

View File

@ -2299,6 +2299,7 @@ static HRESULT WINAPI ddraw3_EnumDisplayModes(IDirectDraw3 *iface, DWORD flags,
{
IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
struct displaymodescallback_context cbcontext;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
iface, flags, surface_desc, context, callback);
@ -2306,7 +2307,8 @@ static HRESULT WINAPI ddraw3_EnumDisplayModes(IDirectDraw3 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc,
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumDisplayModesCallbackThunk);
}
@ -2315,6 +2317,7 @@ static HRESULT WINAPI ddraw2_EnumDisplayModes(IDirectDraw2 *iface, DWORD flags,
{
IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
struct displaymodescallback_context cbcontext;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
iface, flags, surface_desc, context, callback);
@ -2322,7 +2325,8 @@ static HRESULT WINAPI ddraw2_EnumDisplayModes(IDirectDraw2 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc,
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumDisplayModesCallbackThunk);
}
@ -2331,6 +2335,7 @@ static HRESULT WINAPI ddraw1_EnumDisplayModes(IDirectDraw *iface, DWORD flags,
{
IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
struct displaymodescallback_context cbcontext;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
iface, flags, surface_desc, context, callback);
@ -2338,7 +2343,8 @@ static HRESULT WINAPI ddraw1_EnumDisplayModes(IDirectDraw *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc,
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumDisplayModes(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumDisplayModesCallbackThunk);
}
@ -3399,6 +3405,7 @@ static HRESULT WINAPI ddraw3_CreateSurface(IDirectDraw3 *iface, DDSURFACEDESC *s
IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
IDirectDrawSurfaceImpl *impl;
HRESULT hr;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown);
@ -3408,6 +3415,7 @@ static HRESULT WINAPI ddraw3_CreateSurface(IDirectDraw3 *iface, DDSURFACEDESC *s
WARN("Application supplied invalid surface descriptor\n");
return DDERR_INVALIDPARAMS;
}
DDSD_to_DDSD2(surface_desc, &surface_desc2);
if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER))
{
@ -3421,7 +3429,7 @@ static HRESULT WINAPI ddraw3_CreateSurface(IDirectDraw3 *iface, DDSURFACEDESC *s
return DDERR_INVALIDCAPS;
}
hr = CreateSurface(This, (DDSURFACEDESC2 *)surface_desc, &impl, outer_unknown, 3);
hr = CreateSurface(This, &surface_desc2, &impl, outer_unknown, 3);
if (FAILED(hr))
{
*surface = NULL;
@ -3441,6 +3449,7 @@ static HRESULT WINAPI ddraw2_CreateSurface(IDirectDraw2 *iface,
IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
IDirectDrawSurfaceImpl *impl;
HRESULT hr;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown);
@ -3451,6 +3460,7 @@ static HRESULT WINAPI ddraw2_CreateSurface(IDirectDraw2 *iface,
return DDERR_INVALIDPARAMS;
}
DDSD_to_DDSD2(surface_desc, &surface_desc2);
if(surface_desc->ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER | DDSCAPS_BACKBUFFER))
{
if (TRACE_ON(ddraw))
@ -3463,7 +3473,7 @@ static HRESULT WINAPI ddraw2_CreateSurface(IDirectDraw2 *iface,
return DDERR_INVALIDCAPS;
}
hr = CreateSurface(This, (DDSURFACEDESC2 *)surface_desc, &impl, outer_unknown, 2);
hr = CreateSurface(This, &surface_desc2, &impl, outer_unknown, 2);
if (FAILED(hr))
{
*surface = NULL;
@ -3482,6 +3492,7 @@ static HRESULT WINAPI ddraw1_CreateSurface(IDirectDraw *iface,
IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
IDirectDrawSurfaceImpl *impl;
HRESULT hr;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
iface, surface_desc, surface, outer_unknown);
@ -3495,7 +3506,8 @@ static HRESULT WINAPI ddraw1_CreateSurface(IDirectDraw *iface,
/* Remove front buffer flag, this causes failure in v7, and its added to normal
* primaries anyway. */
surface_desc->ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER;
hr = CreateSurface(This, (DDSURFACEDESC2 *)surface_desc, &impl, outer_unknown, 1);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
hr = CreateSurface(This, &surface_desc2, &impl, outer_unknown, 1);
if (FAILED(hr))
{
*surface = NULL;
@ -3738,7 +3750,7 @@ static HRESULT WINAPI ddraw4_EnumSurfaces(IDirectDraw4 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc,
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, surface_desc,
&cbcontext, EnumSurfacesCallback2Thunk);
}
@ -3747,6 +3759,7 @@ static HRESULT WINAPI ddraw3_EnumSurfaces(IDirectDraw3 *iface, DWORD flags,
{
IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
struct surfacescallback_context cbcontext;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
iface, flags, surface_desc, context, callback);
@ -3754,7 +3767,8 @@ static HRESULT WINAPI ddraw3_EnumSurfaces(IDirectDraw3 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc,
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumSurfacesCallbackThunk);
}
@ -3763,6 +3777,7 @@ static HRESULT WINAPI ddraw2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags,
{
IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
struct surfacescallback_context cbcontext;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
iface, flags, surface_desc, context, callback);
@ -3770,7 +3785,8 @@ static HRESULT WINAPI ddraw2_EnumSurfaces(IDirectDraw2 *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc,
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumSurfacesCallbackThunk);
}
@ -3779,6 +3795,7 @@ static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags,
{
IDirectDrawImpl *This = impl_from_IDirectDraw(iface);
struct surfacescallback_context cbcontext;
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
iface, flags, surface_desc, context, callback);
@ -3786,7 +3803,8 @@ static HRESULT WINAPI ddraw1_EnumSurfaces(IDirectDraw *iface, DWORD flags,
cbcontext.func = callback;
cbcontext.context = context;
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, (DDSURFACEDESC2 *)surface_desc,
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw7_EnumSurfaces(&This->IDirectDraw7_iface, flags, &surface_desc2,
&cbcontext, EnumSurfacesCallbackThunk);
}

View File

@ -555,6 +555,7 @@ void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps) DECLSPEC_HIDDEN;
DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) DECLSPEC_HIDDEN;
void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in) DECLSPEC_HIDDEN;
void DDRAW_dump_cooperativelevel(DWORD cooplevel) DECLSPEC_HIDDEN;
void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out) DECLSPEC_HIDDEN;
/* This only needs to be here as long the processvertices functionality of
* IDirect3DExecuteBuffer isn't in WineD3D */

View File

@ -2926,30 +2926,36 @@ static HRESULT WINAPI ddraw_surface3_Initialize(IDirectDrawSurface3 *iface,
IDirectDraw *ddraw, DDSURFACEDESC *surface_desc)
{
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface);
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface,
ddraw, (DDSURFACEDESC2 *)surface_desc);
ddraw, &surface_desc2);
}
static HRESULT WINAPI ddraw_surface2_Initialize(IDirectDrawSurface2 *iface,
IDirectDraw *ddraw, DDSURFACEDESC *surface_desc)
{
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface2(iface);
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface,
ddraw, (DDSURFACEDESC2 *)surface_desc);
ddraw, &surface_desc2);
}
static HRESULT WINAPI ddraw_surface1_Initialize(IDirectDrawSurface *iface,
IDirectDraw *ddraw, DDSURFACEDESC *surface_desc)
{
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface(iface);
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, ddraw %p, surface_desc %p.\n", iface, ddraw, surface_desc);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_Initialize(&This->IDirectDrawSurface7_iface,
ddraw, (DDSURFACEDESC2 *)surface_desc);
ddraw, &surface_desc2);
}
/*****************************************************************************
@ -3939,10 +3945,12 @@ static HRESULT WINAPI ddraw_surface3_SetSurfaceDesc(IDirectDrawSurface3 *iface,
DDSURFACEDESC *surface_desc, DWORD flags)
{
IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface);
DDSURFACEDESC2 surface_desc2;
TRACE("iface %p, surface_desc %p, flags %#x.\n", iface, surface_desc, flags);
DDSD_to_DDSD2(surface_desc, &surface_desc2);
return ddraw_surface7_SetSurfaceDesc(&This->IDirectDrawSurface7_iface,
(DDSURFACEDESC2 *)surface_desc, flags);
&surface_desc2, flags);
}
/*****************************************************************************

View File

@ -1181,3 +1181,41 @@ hr_ddraw_from_wined3d(HRESULT hr)
default: return hr;
}
}
/* Note that this function writes the full sizeof(DDSURFACEDESC2) size, don't use it
* for writing into application-provided DDSURFACEDESC2 structures if the size may
* be different */
void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
{
/* The output of this function is never passed to the application directly, so
* the memset is not strictly needed. CreateSurface still has problems with this
* though. Don't forget to set ddsCaps.dwCaps2/3/4 to 0 when removing this */
memset(out, 0x00, sizeof(*out));
out->dwSize = sizeof(*out);
out->dwFlags = in->dwFlags;
if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
if (in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
/* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
if (in->dwFlags & DDSD_ZBUFFERBITDEPTH)
{
/* FIXME: Convert into a DDPIXELFORMAT */
out->u2.dwMipMapCount = in->u2.dwZBufferBitDepth; /* same union */
}
if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
/* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
out->lpSurface = in->lpSurface;
if (in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
/* Does not exist in DDSURFACEDESC:
* DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
*/
}