From 0a3582865e72d9a8c06540f163ff8b96a6acd0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ri=C4=8Dardas=20Barkauskas?= Date: Wed, 27 Jul 2011 17:43:24 +0300 Subject: [PATCH] ddraw: Use unsafe_impl_from_IDirect3DTexture() for application provided interfaces. --- dlls/ddraw/ddraw_private.h | 2 ++ dlls/ddraw/device.c | 4 ++-- dlls/ddraw/surface.c | 10 +++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 7bce353da2f..6f17912937b 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -253,6 +253,8 @@ IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface * IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface4(IDirectDrawSurface4 *iface) DECLSPEC_HIDDEN; IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface7(IDirectDrawSurface7 *iface) DECLSPEC_HIDDEN; +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirect3DTexture(IDirect3DTexture *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/device.c b/dlls/ddraw/device.c index af6ac27fa1d..eb450990f93 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -568,8 +568,8 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_SwapTextureHandles(IDirect3DDevice * IDirect3DTexture *D3DTex1, IDirect3DTexture *D3DTex2) { IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirectDrawSurfaceImpl *surf1 = surface_from_texture1(D3DTex1); - IDirectDrawSurfaceImpl *surf2 = surface_from_texture1(D3DTex2); + IDirectDrawSurfaceImpl *surf1 = unsafe_impl_from_IDirect3DTexture(D3DTex1); + IDirectDrawSurfaceImpl *surf2 = unsafe_impl_from_IDirect3DTexture(D3DTex2); IDirect3DTexture2 *t1 = surf1 ? (IDirect3DTexture2 *)&surf1->IDirect3DTexture2_vtbl : NULL; IDirect3DTexture2 *t2 = surf2 ? (IDirect3DTexture2 *)&surf2->IDirect3DTexture2_vtbl : NULL; diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index ffda68cc88a..d0e0ab2ecd5 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -4703,10 +4703,11 @@ static HRESULT WINAPI d3d_texture2_Load(IDirect3DTexture2 *iface, IDirect3DTextu static HRESULT WINAPI d3d_texture1_Load(IDirect3DTexture *iface, IDirect3DTexture *src_texture) { + IDirectDrawSurfaceImpl* src_surface = unsafe_impl_from_IDirect3DTexture(src_texture); TRACE("iface %p, src_texture %p.\n", iface, src_texture); return d3d_texture2_Load((IDirect3DTexture2 *)&surface_from_texture1(iface)->IDirect3DTexture2_vtbl, - src_texture ? (IDirect3DTexture2 *)&surface_from_texture1(src_texture)->IDirect3DTexture2_vtbl : NULL); + src_surface ? (IDirect3DTexture2 *)&src_surface->IDirect3DTexture2_vtbl : NULL); } /***************************************************************************** @@ -5028,6 +5029,13 @@ IDirectDrawSurfaceImpl *unsafe_impl_from_IDirectDrawSurface(IDirectDrawSurface * return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirectDrawSurface_iface); } +IDirectDrawSurfaceImpl *unsafe_impl_from_IDirect3DTexture(IDirect3DTexture *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_texture1_vtbl); + return CONTAINING_RECORD(iface, IDirectDrawSurfaceImpl, IDirect3DTexture_vtbl); +} + static void STDMETHODCALLTYPE ddraw_surface_wined3d_object_destroyed(void *parent) { IDirectDrawSurfaceImpl *surface = parent;