From a870753dba5e14191cbbaeb585cc3909ce25dd62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ri=C4=8Dardas=20Barkauskas?= Date: Mon, 17 Oct 2011 16:57:19 +0300 Subject: [PATCH] ddraw: Use unsafe_impl_from_IDirect3DDevice2 for application provided interfaces. --- dlls/ddraw/ddraw_private.h | 1 + dlls/ddraw/device.c | 7 +++++++ dlls/ddraw/material.c | 9 +++++---- dlls/ddraw/surface.c | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index 39b103b4bdb..c8553c2964f 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -341,6 +341,7 @@ static inline IDirect3DDeviceImpl *device_from_device3(IDirect3DDevice3 *iface) } IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice(IDirect3DDevice *iface) DECLSPEC_HIDDEN; +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface) DECLSPEC_HIDDEN; /***************************************************************************** * IDirectDrawClipper implementation structure diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 37a778bc0d8..4d109e4ae90 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -6737,6 +6737,13 @@ static const struct IDirect3DDeviceVtbl d3d_device1_vtbl = IDirect3DDeviceImpl_1_GetDirect3D }; +IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface) +{ + if (!iface) return NULL; + assert(iface->lpVtbl == &d3d_device2_vtbl); + return CONTAINING_RECORD(iface, IDirect3DDeviceImpl, IDirect3DDevice2_vtbl); +} + IDirect3DDeviceImpl *unsafe_impl_from_IDirect3DDevice(IDirect3DDevice *iface) { if (!iface) return NULL; diff --git a/dlls/ddraw/material.c b/dlls/ddraw/material.c index f873726d8b6..236b64740a0 100644 --- a/dlls/ddraw/material.c +++ b/dlls/ddraw/material.c @@ -324,14 +324,15 @@ static HRESULT WINAPI IDirect3DMaterialImpl_GetHandle(IDirect3DMaterial3 *iface, } static HRESULT WINAPI IDirect3DMaterialImpl_2_GetHandle(IDirect3DMaterial2 *iface, - IDirect3DDevice2 *lpDirect3DDevice2, D3DMATERIALHANDLE *lpHandle) + IDirect3DDevice2 *device, D3DMATERIALHANDLE *handle) { IDirect3DMaterialImpl *This = impl_from_IDirect3DMaterial2(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice2(device); - TRACE("iface %p, device %p, handle %p.\n", iface, lpDirect3DDevice2, lpHandle); + TRACE("iface %p, device %p, handle %p.\n", iface, device, handle); - return IDirect3DMaterial3_GetHandle(&This->IDirect3DMaterial3_iface, lpDirect3DDevice2 ? - (IDirect3DDevice3 *)&device_from_device2(lpDirect3DDevice2)->IDirect3DDevice3_vtbl : NULL, lpHandle); + return IDirect3DMaterial3_GetHandle(&This->IDirect3DMaterial3_iface, device_impl ? + (IDirect3DDevice3 *)&device_impl->IDirect3DDevice3_vtbl : NULL, handle); } static HRESULT WINAPI IDirect3DMaterialImpl_1_GetHandle(IDirect3DMaterial *iface, diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index beb759fcfc9..9ef33b3f304 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -4521,6 +4521,7 @@ static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface, IDirect3DDevice2 *device, D3DTEXTUREHANDLE *handle) { IDirectDrawSurfaceImpl *surface = impl_from_IDirect3DTexture2(iface); + IDirect3DDeviceImpl *device_impl = unsafe_impl_from_IDirect3DDevice2(device); TRACE("iface %p, device %p, handle %p.\n", iface, device, handle); @@ -4528,7 +4529,7 @@ static HRESULT WINAPI d3d_texture2_GetHandle(IDirect3DTexture2 *iface, if (!surface->Handle) { - DWORD h = ddraw_allocate_handle(&device_from_device2(device)->handle_table, surface, DDRAW_HANDLE_SURFACE); + DWORD h = ddraw_allocate_handle(&device_impl->handle_table, surface, DDRAW_HANDLE_SURFACE); if (h == DDRAW_INVALID_HANDLE) { ERR("Failed to allocate a texture handle.\n");