From fb6ceb971b3afad0dff63bb860d8595396cf3e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ri=C4=8Dardas=20Barkauskas?= Date: Tue, 31 May 2011 15:49:37 +0300 Subject: [PATCH] ddraw: Use unsafe_impl_from_IDirectDrawSurface3() for application provided interfaces. --- dlls/ddraw/ddraw.c | 21 +++++++++++---------- dlls/ddraw/ddraw_private.h | 2 ++ dlls/ddraw/surface.c | 27 ++++++++++++++++++++------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index c2101b97b0a..d4fbf3b0cf3 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -4160,12 +4160,12 @@ static HRESULT WINAPI ddraw3_DuplicateSurface(IDirectDraw3 *iface, IDirectDrawSu IDirectDrawSurface **dst) { IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); - IDirectDrawSurface7 *src7, *dst7; + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3((IDirectDrawSurface3 *)src); + IDirectDrawSurface7 *dst7; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); - src7 = (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)src); - hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, src7, &dst7); + hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 *)src_impl, &dst7); if (FAILED(hr)) return hr; *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_vtbl; @@ -4176,12 +4176,12 @@ static HRESULT WINAPI ddraw2_DuplicateSurface(IDirectDraw2 *iface, IDirectDrawSurface *src, IDirectDrawSurface **dst) { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); - IDirectDrawSurface7 *src7, *dst7; + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3((IDirectDrawSurface3 *)src); + IDirectDrawSurface7 *dst7; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); - src7 = (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)src); - hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, src7, &dst7); + hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 *)src_impl, &dst7); if (FAILED(hr)) return hr; *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_vtbl; @@ -4192,12 +4192,12 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur IDirectDrawSurface **dst) { IDirectDrawImpl *This = impl_from_IDirectDraw(iface); - IDirectDrawSurface7 *src7, *dst7; + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3((IDirectDrawSurface3 *)src); + IDirectDrawSurface7 *dst7; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); - src7 = (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)src); - hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, src7, &dst7); + hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 *)src_impl, &dst7); if (FAILED(hr)) return hr; *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_vtbl; @@ -4778,13 +4778,14 @@ static HRESULT WINAPI d3d2_CreateDevice(IDirect3D2 *iface, REFCLSID riid, IDirectDrawSurface *surface, IDirect3DDevice2 **device) { IDirectDrawImpl *This = impl_from_IDirect3D2(iface); + IDirectDrawSurfaceImpl *surface_impl = unsafe_impl_from_IDirectDrawSurface3((IDirectDrawSurface3 *)surface); HRESULT hr; TRACE("iface %p, riid %s, surface %p, device %p.\n", iface, debugstr_guid(riid), surface, device); hr = d3d7_CreateDevice(&This->IDirect3D7_iface, riid, - surface ? (IDirectDrawSurface7 *)surface_from_surface3((IDirectDrawSurface3 *)surface) : NULL, + surface_impl ? (IDirectDrawSurface7 *)surface_impl : NULL, (IDirect3DDevice7 **)device); if (*device) *device = (IDirect3DDevice2 *)&((IDirect3DDeviceImpl *)*device)->IDirect3DDevice2_vtbl; diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index e88dda07366..ae77f0c3740 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -225,6 +225,8 @@ static inline IDirectDrawSurfaceImpl *surface_from_surface3(IDirectDrawSurface3 return (IDirectDrawSurfaceImpl *)((char*)iface - FIELD_OFFSET(IDirectDrawSurfaceImpl, IDirectDrawSurface3_vtbl)); } +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface) DECLSPEC_HIDDEN; + /* Get the number of bytes per pixel for a given surface */ #define PFGET_BPP(pf) (pf.dwFlags&DDPF_PALETTEINDEXED8?1:((pf.dwRGBBitCount+7)/8)) #define GET_BPP(desc) PFGET_BPP(desc.ddpfPixelFormat) diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index 0b78b03291d..edd070e766d 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -775,10 +775,11 @@ static HRESULT WINAPI ddraw_surface7_Flip(IDirectDrawSurface7 *iface, IDirectDra static HRESULT WINAPI ddraw_surface3_Flip(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *dst, DWORD flags) { + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst); TRACE("iface %p, dst %p, flags %#x.\n", iface, dst, flags); return ddraw_surface7_Flip((IDirectDrawSurface7 *)surface_from_surface3(iface), - dst ? (IDirectDrawSurface7 *)surface_from_surface3(dst) : NULL, flags); + dst_impl ? (IDirectDrawSurface7 *)dst_impl : NULL, flags); } /***************************************************************************** @@ -871,11 +872,12 @@ static HRESULT WINAPI ddraw_surface7_Blt(IDirectDrawSurface7 *iface, RECT *DestR static HRESULT WINAPI ddraw_surface3_Blt(IDirectDrawSurface3 *iface, RECT *dst_rect, IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags, DDBLTFX *fx) { + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3(src_surface); TRACE("iface %p, dst_rect %s, src_surface %p, src_rect %s, flags %#x, fx %p.\n", iface, wine_dbgstr_rect(dst_rect), src_surface, wine_dbgstr_rect(src_rect), flags, fx); return ddraw_surface7_Blt((IDirectDrawSurface7 *)surface_from_surface3(iface), dst_rect, - src_surface ? (IDirectDrawSurface7 *)surface_from_surface3(src_surface) : NULL, src_rect, flags, fx); + src_impl ? (IDirectDrawSurface7 *)src_impl : NULL, src_rect, flags, fx); } /***************************************************************************** @@ -982,7 +984,7 @@ static HRESULT WINAPI ddraw_surface7_AddAttachedSurface(IDirectDrawSurface7 *ifa static HRESULT WINAPI ddraw_surface3_AddAttachedSurface(IDirectDrawSurface3 *iface, IDirectDrawSurface3 *attachment) { IDirectDrawSurfaceImpl *surface = surface_from_surface3(iface); - IDirectDrawSurfaceImpl *attach_impl = surface_from_surface3(attachment); + IDirectDrawSurfaceImpl *attach_impl = unsafe_impl_from_IDirectDrawSurface3(attachment); TRACE("iface %p, attachment %p.\n", iface, attachment); @@ -1086,10 +1088,11 @@ static HRESULT WINAPI ddraw_surface7_DeleteAttachedSurface(IDirectDrawSurface7 * static HRESULT WINAPI ddraw_surface3_DeleteAttachedSurface(IDirectDrawSurface3 *iface, DWORD flags, IDirectDrawSurface3 *attachment) { + IDirectDrawSurfaceImpl *attachment_impl = unsafe_impl_from_IDirectDrawSurface3(attachment); TRACE("iface %p, flags %#x, attachment %p.\n", iface, flags, attachment); return ddraw_surface7_DeleteAttachedSurface((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, - attachment ? (IDirectDrawSurface7 *)surface_from_surface3(attachment) : NULL); + attachment_impl ? (IDirectDrawSurface7 *)attachment_impl : NULL); } /***************************************************************************** @@ -2092,11 +2095,12 @@ static HRESULT WINAPI ddraw_surface7_UpdateOverlay(IDirectDrawSurface7 *iface, R static HRESULT WINAPI ddraw_surface3_UpdateOverlay(IDirectDrawSurface3 *iface, RECT *src_rect, IDirectDrawSurface3 *dst_surface, RECT *dst_rect, DWORD flags, DDOVERLAYFX *fx) { + IDirectDrawSurfaceImpl *dst_impl = unsafe_impl_from_IDirectDrawSurface3(dst_surface); TRACE("iface %p, src_rect %s, dst_surface %p, dst_rect %s, flags %#x, fx %p.\n", iface, wine_dbgstr_rect(src_rect), dst_surface, wine_dbgstr_rect(dst_rect), flags, fx); return ddraw_surface7_UpdateOverlay((IDirectDrawSurface7 *)surface_from_surface3(iface), src_rect, - dst_surface ? (IDirectDrawSurface7 *)surface_from_surface3(dst_surface) : NULL, dst_rect, flags, fx); + dst_impl ? (IDirectDrawSurface7 *)dst_impl : NULL, dst_rect, flags, fx); } /***************************************************************************** @@ -2156,10 +2160,11 @@ static HRESULT WINAPI ddraw_surface7_UpdateOverlayZOrder(IDirectDrawSurface7 *if static HRESULT WINAPI ddraw_surface3_UpdateOverlayZOrder(IDirectDrawSurface3 *iface, DWORD flags, IDirectDrawSurface3 *reference) { + IDirectDrawSurfaceImpl *reference_impl = unsafe_impl_from_IDirectDrawSurface3(reference); TRACE("iface %p, flags %#x, reference %p.\n", iface, flags, reference); return ddraw_surface7_UpdateOverlayZOrder((IDirectDrawSurface7 *)surface_from_surface3(iface), flags, - reference ? (IDirectDrawSurface7 *)surface_from_surface3(reference) : NULL); + reference_impl ? (IDirectDrawSurface7 *)reference_impl : NULL); } /***************************************************************************** @@ -2408,11 +2413,12 @@ static HRESULT WINAPI ddraw_surface7_BltFast(IDirectDrawSurface7 *iface, DWORD d static HRESULT WINAPI ddraw_surface3_BltFast(IDirectDrawSurface3 *iface, DWORD dst_x, DWORD dst_y, IDirectDrawSurface3 *src_surface, RECT *src_rect, DWORD flags) { + IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3(src_surface); TRACE("iface %p, dst_x %u, dst_y %u, src_surface %p, src_rect %s, flags %#x.\n", iface, dst_x, dst_y, src_surface, wine_dbgstr_rect(src_rect), flags); return ddraw_surface7_BltFast((IDirectDrawSurface7 *)surface_from_surface3(iface), dst_x, dst_y, - src_surface ? (IDirectDrawSurface7 *)surface_from_surface3(src_surface) : NULL, src_rect, flags); + src_impl ? (IDirectDrawSurface7 *)src_impl : NULL, src_rect, flags); } /***************************************************************************** @@ -3399,6 +3405,13 @@ static const struct IDirect3DTextureVtbl d3d_texture1_vtbl = d3d_texture1_Unload, }; +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface3(IDirectDrawSurface3 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &ddraw_surface3_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface3_vtbl); +} + static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *parent) { IDirectDrawSurfaceImpl *surface = parent;