[PATCH 3/4] d3d9: Use unsafe_impl_from_IDirect3DPixelShader9 for an app provided iface.

Michael Stefaniuc mstefani at redhat.de
Tue Jul 5 05:03:20 CDT 2011


---
 dlls/d3d9/d3d9_private.h |    1 +
 dlls/d3d9/device.c       |    3 ++-
 dlls/d3d9/shader.c       |   15 +++++++++++++++
 3 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index b259ed5..db783d8 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -437,6 +437,7 @@ typedef struct IDirect3DPixelShader9Impl {
 
 HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader,
         IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN;
+IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface) DECLSPEC_HIDDEN;
 
 /* --------------- */
 /* IDirect3DQuery9 */
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index 89f292a..2f7a38f 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -2607,13 +2607,14 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *if
         IDirect3DPixelShader9 *shader)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DPixelShader9Impl *shader_obj = unsafe_impl_from_IDirect3DPixelShader9(shader);
     HRESULT hr;
 
     TRACE("iface %p, shader %p.\n", iface, shader);
 
     wined3d_mutex_lock();
     hr = wined3d_device_set_pixel_shader(This->wined3d_device,
-            shader ? ((IDirect3DPixelShader9Impl *)shader)->wined3d_shader : NULL);
+            shader_obj ? shader_obj->wined3d_shader : NULL);
     wined3d_mutex_unlock();
 
     return hr;
diff --git a/dlls/d3d9/shader.c b/dlls/d3d9/shader.c
index c36600d..66f1c07 100644
--- a/dlls/d3d9/shader.c
+++ b/dlls/d3d9/shader.c
@@ -18,6 +18,7 @@
  */
 
 #include "config.h"
+#include <assert.h>
 #include "d3d9_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
@@ -150,6 +151,11 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Im
     return D3D_OK;
 }
 
+static inline IDirect3DPixelShader9Impl *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DPixelShader9Impl, lpVtbl);
+}
+
 static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **object)
 {
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
@@ -276,3 +282,12 @@ HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl
 
     return D3D_OK;
 }
+
+IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d9_pixelshader_vtbl);
+
+    return impl_from_IDirect3DPixelShader9(iface);
+}
-- 
1.7.4.4



More information about the wine-patches mailing list