H. Verbeet : d3d8: Use proper handles for pixel shaders.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Aug 28 05:09:27 CDT 2006


Module: wine
Branch: master
Commit: 9a4ce31737e706aa7a6bb8ea58b1a321dde1dc32
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=9a4ce31737e706aa7a6bb8ea58b1a321dde1dc32

Author: H. Verbeet <hverbeet at gmail.com>
Date:   Sun Aug 27 22:07:13 2006 +0200

d3d8: Use proper handles for pixel shaders.

---

 dlls/d3d8/d3d8_private.h |    1 +
 dlls/d3d8/device.c       |   47 ++++++++++++++++++++++++++++++++++++----------
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index b3af102..b32033f 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -560,6 +560,7 @@ typedef struct IDirect3DPixelShader8Impl
     const IDirect3DPixelShader8Vtbl *lpVtbl;
     LONG                             ref;
 
+    shader_handle                   *handle;
     /* The device, to be replaced by an IDirect3DDeviceImpl */
     IWineD3DPixelShader             *wineD3DPixelShader;
 } IDirect3DPixelShader8Impl;
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 6997df7..0950f72 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -1262,6 +1262,8 @@ static HRESULT WINAPI IDirect3DDevice8Im
     IDirect3DPixelShader8Impl *object;
     HRESULT hrc = D3D_OK;
 
+    TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
+
     if (NULL == ppShader) {
         TRACE("(%p) Invalid call\n", This);
         return D3DERR_INVALIDCALL;
@@ -1280,20 +1282,37 @@ static HRESULT WINAPI IDirect3DDevice8Im
             HeapFree(GetProcessHeap(), 0 , object);
             *ppShader = 0;
         } else {
-            *ppShader = (DWORD)object;
+            shader_handle *handle = alloc_shader_handle(This);
+            if (!handle) {
+                ERR("Failed to allocate shader handle\n");
+                IDirect3DVertexShader8_Release((IUnknown *)object);
+                hrc = E_OUTOFMEMORY;
+            } else {
+                object->handle = handle;
+                *handle = object;
+                *ppShader = (handle - This->shader_handles) + VS_HIGHESTFIXEDFXF + 1;
+            }
         }
 
     }
 
-    TRACE("(%p) : returning %p\n", This, (void *)*ppShader);
+    TRACE("(%p) : returning %p (handle %#lx)\n", This, object, *ppShader);
     return hrc;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_SetPixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DPixelShader8Impl *shader = (IDirect3DPixelShader8Impl *)pShader;
-    TRACE("(%p) Relay\n", This);
+    IDirect3DPixelShader8Impl *shader = NULL;
 
+    TRACE("(%p) : pShader %#lx\n", This, pShader);
+
+    if (pShader > VS_HIGHESTFIXEDFXF && This->allocated_shader_handles > pShader - (VS_HIGHESTFIXEDFXF + 1)) {
+        shader = This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
+    } else if (pShader) {
+        ERR("Trying to set an invalid handle.\n");
+    }
+
+    TRACE("(%p) : Setting shader %p\n", This, shader);
     return IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
 }
 
@@ -1310,23 +1329,31 @@ static HRESULT WINAPI IDirect3DDevice8Im
 
     hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
     if (D3D_OK == hrc && NULL != object) {
-       hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)ppShader);
-       IWineD3DPixelShader_Release(object);
+        IDirect3DPixelShader8Impl *d3d8_shader;
+        hrc = IWineD3DPixelShader_GetParent(object, (IUnknown **)&d3d8_shader);
+        IWineD3DPixelShader_Release(object);
+        *ppShader = (d3d8_shader->handle - This->shader_handles) + (VS_HIGHESTFIXEDFXF + 1);
     } else {
         *ppShader = (DWORD)NULL;
     }
 
-    TRACE("(%p) : returning %p\n", This, (void *)*ppShader);
+    TRACE("(%p) : returning %#lx\n", This, *ppShader);
     return hrc;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_DeletePixelShader(LPDIRECT3DDEVICE8 iface, DWORD pShader) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DPixelShader8Impl *shader = (IDirect3DPixelShader8Impl *)pShader;
-    TRACE("(%p) Relay\n", This);
 
-    if (NULL != shader) {
+    TRACE("(%p) : pShader %#lx\n", This, pShader);
+
+    if (pShader <= VS_HIGHESTFIXEDFXF || This->allocated_shader_handles <= pShader - (VS_HIGHESTFIXEDFXF + 1)) {
+        ERR("(%p) : Trying to delete an invalid handle\n", This);
+        return D3DERR_INVALIDCALL;
+    } else {
+        shader_handle *handle = &This->shader_handles[pShader - (VS_HIGHESTFIXEDFXF + 1)];
+        IDirect3DPixelShader8Impl *shader = *handle;
         while(IUnknown_Release((IUnknown *)shader));
+        free_shader_handle(This, handle);
     }
 
     return D3D_OK;




More information about the wine-cvs mailing list