Fix ref-counting rules to match native DCOM Dlls.
[wine] / dlls / wined3d / pixelshader.c
1 /*
2  * shaders implementation
3  *
4  * Copyright 2005      Oliver Stieber
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <math.h>
24
25 #include "wined3d_private.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
28
29
30 /* *******************************************
31    IWineD3DPixelShader IUnknown parts follow
32    ******************************************* */
33 HRESULT WINAPI IWineD3DPixelShaderImpl_QueryInterface(IWineD3DPixelShader *iface, REFIID riid, LPVOID *ppobj)
34 {
35     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
36     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
37     if (IsEqualGUID(riid, &IID_IUnknown)
38         || IsEqualGUID(riid, &IID_IWineD3DPixelShader)) {
39         IUnknown_AddRef(iface);
40         *ppobj = This;
41         return D3D_OK;
42     }
43     return E_NOINTERFACE;
44 }
45
46 ULONG WINAPI IWineD3DPixelShaderImpl_AddRef(IWineD3DPixelShader *iface) {
47     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
48     TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref);
49     return InterlockedIncrement(&This->ref);
50 }
51
52 ULONG WINAPI IWineD3DPixelShaderImpl_Release(IWineD3DPixelShader *iface) {
53     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
54     ULONG ref;
55     TRACE("(%p) : Releasing from %ld\n", This, This->ref);
56     ref = InterlockedDecrement(&This->ref);
57     if (ref == 0) {
58         HeapFree(GetProcessHeap(), 0, This);
59     }
60     return ref;
61 }
62
63 /* *******************************************
64    IWineD3DPixelShader IWineD3DPixelShader parts follow
65    ******************************************* */
66
67 HRESULT WINAPI IWineD3DPixelShaderImpl_GetParent(IWineD3DPixelShader *iface, IUnknown** parent){
68     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
69
70     *parent= (IUnknown*) parent;
71     IUnknown_AddRef(*parent);
72     TRACE("(%p) : returning %p\n", This, *parent);
73     return D3D_OK;
74 }
75    
76 HRESULT WINAPI IWineD3DPixelShaderImpl_GetDevice(IWineD3DPixelShader* iface, IWineD3DDevice **pDevice){
77     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
78     IWineD3DDevice_AddRef((IWineD3DDevice *)This->wineD3DDevice);
79     *pDevice = (IWineD3DDevice *)This->wineD3DDevice;
80     TRACE("(%p) returning %p\n", This, *pDevice);
81     return D3D_OK;
82 }
83
84
85 HRESULT WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader* impl, VOID* pData, UINT* pSizeOfData) {
86   IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)impl;
87   FIXME("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
88
89   if (NULL == pData) {
90     *pSizeOfData = This->functionLength;
91     return D3D_OK;
92   }
93   if (*pSizeOfData < This->functionLength) {
94     *pSizeOfData = This->functionLength;
95     return D3DERR_MOREDATA;
96   }
97   if (NULL == This->function) { /* no function defined */
98     TRACE("(%p) : GetFunction no User Function defined using NULL to %p\n", This, pData);
99     (*(DWORD **) pData) = NULL;
100   } else {
101     if(This->functionLength == 0){
102
103     }
104     TRACE("(%p) : GetFunction copying to %p\n", This, pData);
105     memcpy(pData, This->function, This->functionLength);
106   }
107   return D3D_OK;
108 }
109
110
111
112 const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
113 {
114     /*** IUnknown methods ***/
115     IWineD3DPixelShaderImpl_QueryInterface,
116     IWineD3DPixelShaderImpl_AddRef,
117     IWineD3DPixelShaderImpl_Release,
118     /*** IWineD3DPixelShader methods ***/
119     IWineD3DPixelShaderImpl_GetParent,
120     IWineD3DPixelShaderImpl_GetDevice,
121     IWineD3DPixelShaderImpl_GetFunction
122 };