Commit c5d2f5ef authored by Marcus Meissner's avatar Marcus Meissner Committed by Alexandre Julliard

Handle differently sized structs by using their dwSize parameters.

parent 45edb2fc
...@@ -283,7 +283,8 @@ create_texture(IDirectDrawImpl* This, const DDSURFACEDESC2 *pDDSD, ...@@ -283,7 +283,8 @@ create_texture(IDirectDrawImpl* This, const DDSURFACEDESC2 *pDDSD,
if ((pDDSD->dwFlags&(DDSD_HEIGHT|DDSD_WIDTH)) != (DDSD_HEIGHT|DDSD_WIDTH)) if ((pDDSD->dwFlags&(DDSD_HEIGHT|DDSD_WIDTH)) != (DDSD_HEIGHT|DDSD_WIDTH))
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
ddsd = *pDDSD; ddsd.dwSize = sizeof(ddsd);
DD_STRUCT_COPY_BYSIZE((&ddsd),pDDSD);
if (!(ddsd.dwFlags & DDSD_PIXELFORMAT)) if (!(ddsd.dwFlags & DDSD_PIXELFORMAT))
{ {
...@@ -365,7 +366,8 @@ create_primary(IDirectDrawImpl* This, LPDDSURFACEDESC2 pDDSD, ...@@ -365,7 +366,8 @@ create_primary(IDirectDrawImpl* This, LPDDSURFACEDESC2 pDDSD,
if (pDDSD->dwFlags & (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT)) if (pDDSD->dwFlags & (DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT))
return DDERR_INVALIDPARAMS; 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.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH | DDSD_PIXELFORMAT;
ddsd.dwHeight = This->height; ddsd.dwHeight = This->height;
ddsd.dwWidth = This->width; ddsd.dwWidth = This->width;
...@@ -438,7 +440,8 @@ create_offscreen(IDirectDrawImpl* This, LPDDSURFACEDESC2 pDDSD, ...@@ -438,7 +440,8 @@ create_offscreen(IDirectDrawImpl* This, LPDDSURFACEDESC2 pDDSD,
if ((pDDSD->dwFlags&(DDSD_HEIGHT|DDSD_WIDTH)) != (DDSD_HEIGHT|DDSD_WIDTH)) if ((pDDSD->dwFlags&(DDSD_HEIGHT|DDSD_WIDTH)) != (DDSD_HEIGHT|DDSD_WIDTH))
return DDERR_INVALIDPARAMS; return DDERR_INVALIDPARAMS;
ddsd = *pDDSD; ddsd.dwSize = sizeof(ddsd);
DD_STRUCT_COPY_BYSIZE((&ddsd),pDDSD);
if (!(ddsd.dwFlags & DDSD_PIXELFORMAT)) if (!(ddsd.dwFlags & DDSD_PIXELFORMAT))
{ {
......
...@@ -213,8 +213,6 @@ IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc, ...@@ -213,8 +213,6 @@ IDirectDraw2Impl_CreateSurface(LPDIRECTDRAW2 This, LPDDSURFACEDESC pSDesc,
LPDIRECTDRAWSURFACE7 pSurface7; LPDIRECTDRAWSURFACE7 pSurface7;
HRESULT hr; HRESULT hr;
/* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
* since the data layout is the same */
hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl, hr = IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
IDirectDraw2, IDirectDraw2,
IDirectDraw7, IDirectDraw7,
...@@ -235,13 +233,11 @@ IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc, ...@@ -235,13 +233,11 @@ IDirectDraw4Impl_CreateSurface(LPDIRECTDRAW4 This, LPDDSURFACEDESC2 pSDesc,
LPDIRECTDRAWSURFACE4 *ppSurface, LPDIRECTDRAWSURFACE4 *ppSurface,
IUnknown *pUnkOuter) IUnknown *pUnkOuter)
{ {
/* the LPDDSURFACEDESC -> LPDDSURFACEDESC2 conversion should be ok,
* since the data layout is the same */
return IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl, return IDirectDraw7_CreateSurface(COM_INTERFACE_CAST(IDirectDrawImpl,
IDirectDraw4, IDirectDraw4,
IDirectDraw7, IDirectDraw7,
This), This),
(LPDDSURFACEDESC2)pSDesc, pSDesc,
(LPDIRECTDRAWSURFACE7 *)ppSurface, (LPDIRECTDRAWSURFACE7 *)ppSurface,
pUnkOuter); pUnkOuter);
} }
......
...@@ -445,10 +445,10 @@ User_DirectDraw_GetCaps(LPDIRECTDRAW7 iface, LPDDCAPS pDriverCaps, ...@@ -445,10 +445,10 @@ User_DirectDraw_GetCaps(LPDIRECTDRAW7 iface, LPDDCAPS pDriverCaps,
} }
if (pDriverCaps != NULL) if (pDriverCaps != NULL)
memcpy(pDriverCaps, &caps, pDriverCaps->dwSize); DD_STRUCT_COPY_BYSIZE(pDriverCaps,&caps);
if (pHELCaps != NULL) if (pHELCaps != NULL)
memcpy(pHELCaps, &caps, pHELCaps->dwSize); DD_STRUCT_COPY_BYSIZE(pHELCaps,&caps);
return DD_OK; return DD_OK;
} }
......
...@@ -21,9 +21,12 @@ ...@@ -21,9 +21,12 @@
#define DD_STRUCT_COPY_BYSIZE(to,from) \ #define DD_STRUCT_COPY_BYSIZE(to,from) \
do { \ do { \
DWORD __size = to->dwSize; \ DWORD __size = (to)->dwSize; \
memcpy(to,from,__size); \ DWORD __copysize = __size; \
to->dwSize = __size;/*restore size*/ \ if ((from)->dwSize < __size) \
__copysize = (from)->dwSize; \
memcpy(to,from,__copysize); \
(to)->dwSize = __size;/*restore size*/ \
} while (0) } while (0)
/***************************************************************************** /*****************************************************************************
......
...@@ -25,8 +25,10 @@ Main_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This, ...@@ -25,8 +25,10 @@ Main_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl *This,
IDirectDrawImpl *pDD, IDirectDrawImpl *pDD,
const DDSURFACEDESC2 *pDDSD) const DDSURFACEDESC2 *pDDSD)
{ {
if (pDDSD != &This->surface_desc) if (pDDSD != &This->surface_desc) {
This->surface_desc = *pDDSD; This->surface_desc.dwSize = sizeof(This->surface_desc);
DD_STRUCT_COPY_BYSIZE(&(This->surface_desc),pDDSD);
}
This->uniqueness_value = 1; /* unchecked */ This->uniqueness_value = 1; /* unchecked */
This->ref = 1; This->ref = 1;
...@@ -680,7 +682,7 @@ Main_DirectDrawSurface_GetPixelFormat(LPDIRECTDRAWSURFACE7 iface, ...@@ -680,7 +682,7 @@ Main_DirectDrawSurface_GetPixelFormat(LPDIRECTDRAWSURFACE7 iface,
ICOM_THIS(IDirectDrawSurfaceImpl, iface); ICOM_THIS(IDirectDrawSurfaceImpl, iface);
TRACE("(%p)->(%p)\n",This,pDDPixelFormat); 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; return DD_OK;
} }
...@@ -793,7 +795,8 @@ Main_DirectDrawSurface_Lock(LPDIRECTDRAWSURFACE7 iface, LPRECT prect, ...@@ -793,7 +795,8 @@ Main_DirectDrawSurface_Lock(LPDIRECTDRAWSURFACE7 iface, LPRECT prect,
This,prect,pDDSD,flags,(DWORD)h); This,prect,pDDSD,flags,(DWORD)h);
/* First, copy the Surface description */ /* 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", TRACE("locked surface: height=%ld, width=%ld, pitch=%ld\n",
pDDSD->dwHeight,pDDSD->dwWidth,pDDSD->u1.lPitch); pDDSD->dwHeight,pDDSD->dwWidth,pDDSD->u1.lPitch);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment