Return the correct error code from IConnectionPointContainer::FindConnectionPoint.
[wine] / dlls / d3d9 / stateblock.c
1 /*
2  * IDirect3DStateBlock9 implementation
3  *
4  * Copyright 2002-2003 Raphael Junqueira
5  * Copyright 2002-2003 Jason Edmeades
6  * Copyright 2005 Oliver Stieber
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28 /* IDirect3DStateBlock9 IUnknown parts follow: */
29 HRESULT WINAPI IDirect3DStateBlock9Impl_QueryInterface(LPDIRECT3DSTATEBLOCK9 iface, REFIID riid, LPVOID* ppobj) {
30     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
31
32     if (IsEqualGUID(riid, &IID_IUnknown)
33         || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
34         IUnknown_AddRef(iface);
35         *ppobj = This;
36         return D3D_OK;
37     }
38
39     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
40     return E_NOINTERFACE;
41 }
42
43 ULONG WINAPI IDirect3DStateBlock9Impl_AddRef(LPDIRECT3DSTATEBLOCK9 iface) {
44     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
48
49     return ref;
50 }
51
52 ULONG WINAPI IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface) {
53     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
57
58     if (ref == 0) {
59         IWineD3DStateBlock_Release(This->wineD3DStateBlock);    
60         HeapFree(GetProcessHeap(), 0, This);
61     }
62     return ref;
63 }
64
65 /* IDirect3DStateBlock9 Interface follow: */
66 HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(LPDIRECT3DSTATEBLOCK9 iface, IDirect3DDevice9** ppDevice) {
67     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
68     TRACE("(%p) Relay\n", This); 
69     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
70 }
71
72 HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
73     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
74     TRACE("(%p) Relay\n", This); 
75     return IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
76 }
77
78 HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface) {
79     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
80     TRACE("(%p) Relay\n", This); 
81     return IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
82 }
83
84
85 const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl =
86 {
87     /* IUnknown */
88     IDirect3DStateBlock9Impl_QueryInterface,
89     IDirect3DStateBlock9Impl_AddRef,
90     IDirect3DStateBlock9Impl_Release,
91     /* IDirect3DStateBlock9 */
92     IDirect3DStateBlock9Impl_GetDevice,
93     IDirect3DStateBlock9Impl_Capture,
94     IDirect3DStateBlock9Impl_Apply
95 };
96
97
98 /* IDirect3DDevice9 IDirect3DStateBlock9 Methods follow: */
99 HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9 iface, D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppStateBlock) {
100    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
101    IDirect3DStateBlock9Impl* object;
102    HRESULT hrc = D3D_OK;
103    
104    TRACE("(%p) Relay\n", This);
105    
106    object  = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
107    if (NULL == object) {
108       FIXME("(%p)  Failed to allocate %d bytes\n", This, sizeof(IDirect3DStateBlock9Impl));
109       return E_OUTOFMEMORY;
110    }
111    object->lpVtbl = &Direct3DStateBlock9_Vtbl;
112    object->ref = 1;
113    
114    hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown*)object);
115    if(hrc != D3D_OK){
116        FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
117        HeapFree(GetProcessHeap(), 0, object);
118    } else {
119        *ppStateBlock = (IDirect3DStateBlock9*)object;
120        TRACE("(%p) : Created stateblock %p\n", This, object);
121    }
122    TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
123    return hrc;
124 }
125
126 HRESULT  WINAPI  IDirect3DDevice9Impl_BeginStateBlock(LPDIRECT3DDEVICE9 iface) {
127     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
128     TRACE("(%p) Relay\n", This); 
129     return IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
130 }
131
132 HRESULT  WINAPI  IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9 iface, IDirect3DStateBlock9** ppSB) {
133     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
134     HRESULT hr;
135     IWineD3DStateBlock* wineD3DStateBlock;    
136     IDirect3DStateBlock9Impl* object;
137
138     TRACE("(%p) Relay\n", This); 
139     
140     /* Tell wineD3D to endstatablock before anything else (in case we run out
141      * of memory later and cause locking problems)
142      */
143     hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
144     if(hr!= D3D_OK){
145        FIXME("IWineD3DDevice_EndStateBlock returned an error\n");
146        return hr;
147     }    
148     /* allocate a new IDirectD3DStateBlock */
149     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock9Impl));      
150     object->ref = 1;
151     object->lpVtbl = &Direct3DStateBlock9_Vtbl;
152       
153     object->wineD3DStateBlock=wineD3DStateBlock;
154   
155     *ppSB=(IDirect3DStateBlock9*)object;        
156     TRACE("(%p)Returning %p %p\n", This, *ppSB, wineD3DStateBlock);
157     return D3D_OK;
158 }