Handle differently sized structs by using their dwSize parameters.
This commit is contained in:
parent
45edb2fcb3
commit
c5d2f5efeb
|
@ -283,7 +283,8 @@ create_texture(IDirectDrawImpl* This, const DDSURFACEDESC2 *pDDSD,
|
|||
if ((pDDSD->dwFlags&(DDSD_HEIGHT|DDSD_WIDTH)) != (DDSD_HEIGHT|DDSD_WIDTH))
|
||||
return DDERR_INVALIDPARAMS;
|
||||
|
||||
ddsd = *pDDSD;
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
DD_STRUCT_COPY_BYSIZE((&ddsd),pDDSD);
|
||||
|
||||
if (!(ddsd.dwFlags & DDSD_PIXELFORMAT))
|
||||
{
|
||||
|
@ -365,7 +366,8 @@ create_primary(IDirectDrawImpl* This, LPDDSURFACEDESC2 pDDSD,
|
|||
if (pDDSD->dwFlags & (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT))
|
||||
return DDERR_INVALIDPARAMS;
|
||||
|
||||
ddsd = *pDDSD;
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
DD_STRUCT_COPY_BYSIZE((&ddsd),pDDSD);
|
||||
ddsd.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH | DDSD_PIXELFORMAT;
|
||||
ddsd.dwHeight = This->height;
|
||||
ddsd.dwWidth = This->width;
|
||||
|
@ -438,7 +440,8 @@ create_offscreen(IDirectDrawImpl* This, LPDDSURFACEDESC2 pDDSD,
|
|||
if ((pDDSD->dwFlags&(DDSD_HEIGHT|DDSD_WIDTH)) != (DDSD_HEIGHT|DDSD_WIDTH))
|
||||
return DDERR_INVALIDPARAMS;
|
||||
|
||||
ddsd = *pDDSD;
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
DD_STRUCT_COPY_BYSIZE((&ddsd),pDDSD);
|
||||
|
||||
if (!(ddsd.dwFlags & DDSD_PIXELFORMAT))
|
||||
{
|
||||
|
|
|
@ -213,8 +213,6 @@ IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc,
|
|||
LPDIRECTDRAWSURFACE7 pSurface7;
|
||||
HRESULT hr;
|
||||
|
||||
/* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
|
||||
* since the data layout is the same */
|
||||
hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
|
||||
IDirectDraw2,
|
||||
IDirectDraw7,
|
||||
|
@ -235,13 +233,11 @@ IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
|
|||
LPDIRECTDRAWSURFACE4 *ppSurface,
|
||||
IUnknown *pUnkOuter)
|
||||
{
|
||||
/* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
|
||||
* since the data layout is the same */
|
||||
return IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
|
||||
IDirectDraw4,
|
||||
IDirectDraw7,
|
||||
This),
|
||||
(LPDDSURFACEDESC2)pSDesc,
|
||||
pSDesc,
|
||||
(LPDIRECTDRAWSURFACE7 *)ppSurface,
|
||||
pUnkOuter);
|
||||
}
|
||||
|
|
|
@ -445,10 +445,10 @@ User_DirectDraw_GetCaps(LPDIRECTDRAW7 iface, LPDDCAPS pDriverCaps,
|
|||
}
|
||||
|
||||
if (pDriverCaps != NULL)
|
||||
memcpy(pDriverCaps, &caps, pDriverCaps->dwSize);
|
||||
DD_STRUCT_COPY_BYSIZE(pDriverCaps,&caps);
|
||||
|
||||
if (pHELCaps != NULL)
|
||||
memcpy(pHELCaps, &caps, pHELCaps->dwSize);
|
||||
DD_STRUCT_COPY_BYSIZE(pHELCaps,&caps);
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
|
|
|
@ -21,9 +21,12 @@
|
|||
|
||||
#define DD_STRUCT_COPY_BYSIZE(to,from) \
|
||||
do { \
|
||||
DWORD __size = to->dwSize; \
|
||||
memcpy(to,from,__size); \
|
||||
to->dwSize = __size;/*restore size*/ \
|
||||
DWORD __size = (to)->dwSize; \
|
||||
DWORD __copysize = __size; \
|
||||
if ((from)->dwSize < __size) \
|
||||
__copysize = (from)->dwSize; \
|
||||
memcpy(to,from,__copysize); \
|
||||
(to)->dwSize = __size;/*restore size*/ \
|
||||
} while (0)
|
||||
|
||||
/*****************************************************************************
|
||||
|
|
|
@ -25,8 +25,10 @@ Main_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
|
|||
IDirectDrawImpl *pDD,
|
||||
const DDSURFACEDESC2 *pDDSD)
|
||||
{
|
||||
if (pDDSD != &This->surface_desc)
|
||||
This->surface_desc = *pDDSD;
|
||||
if (pDDSD != &This->surface_desc) {
|
||||
This->surface_desc.dwSize = sizeof(This->surface_desc);
|
||||
DD_STRUCT_COPY_BYSIZE(&(This->surface_desc),pDDSD);
|
||||
}
|
||||
This->uniqueness_value = 1; /* unchecked */
|
||||
This->ref = 1;
|
||||
|
||||
|
@ -680,7 +682,7 @@ Main_DirectDrawSurface_GetPixelFormat(LPDIRECTDRAWSURFACE7 iface,
|
|||
ICOM_THIS(IDirectDrawSurfaceImpl, iface);
|
||||
|
||||
TRACE("(%p)->(%p)\n",This,pDDPixelFormat);
|
||||
*pDDPixelFormat = This->surface_desc.u4.ddpfPixelFormat;
|
||||
DD_STRUCT_COPY_BYSIZE(pDDPixelFormat,&This->surface_desc.u4.ddpfPixelFormat);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
|
@ -793,7 +795,8 @@ Main_DirectDrawSurface_Lock(LPDIRECTDRAWSURFACE7 iface, LPRECT prect,
|
|||
This,prect,pDDSD,flags,(DWORD)h);
|
||||
|
||||
/* First, copy the Surface description */
|
||||
memcpy(pDDSD, &(This->surface_desc), pDDSD->dwSize);
|
||||
DD_STRUCT_COPY_BYSIZE(pDDSD,&(This->surface_desc));
|
||||
|
||||
TRACE("locked surface: height=%ld, width=%ld, pitch=%ld\n",
|
||||
pDDSD->dwHeight,pDDSD->dwWidth,pDDSD->u1.lPitch);
|
||||
|
||||
|
|
Loading…
Reference in New Issue