VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c@ 23571

Last change on this file since 23571 was 23571, checked in by vboxsync, 16 years ago

crOpenGL: update to wine 1.1.30

  • Property svn:eol-style set to native
File size: 7.3 KB
Line 
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23/*
24 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "d3d9_private.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
36
37/* IDirect3DStateBlock9 IUnknown parts follow: */
38static HRESULT WINAPI IDirect3DStateBlock9Impl_QueryInterface(LPDIRECT3DSTATEBLOCK9 iface, REFIID riid, LPVOID* ppobj) {
39 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
40
41 if (IsEqualGUID(riid, &IID_IUnknown)
42 || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
43 IDirect3DStateBlock9_AddRef(iface);
44 *ppobj = This;
45 return S_OK;
46 }
47
48 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
49 *ppobj = NULL;
50 return E_NOINTERFACE;
51}
52
53static ULONG WINAPI IDirect3DStateBlock9Impl_AddRef(LPDIRECT3DSTATEBLOCK9 iface) {
54 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
55 ULONG ref = InterlockedIncrement(&This->ref);
56
57 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
58
59 return ref;
60}
61
62static ULONG WINAPI IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface) {
63 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
64 ULONG ref = InterlockedDecrement(&This->ref);
65
66 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
67
68 if (ref == 0) {
69 wined3d_mutex_lock();
70 IWineD3DStateBlock_Release(This->wineD3DStateBlock);
71 wined3d_mutex_unlock();
72
73 IDirect3DDevice9Ex_Release(This->parentDevice);
74 HeapFree(GetProcessHeap(), 0, This);
75 }
76 return ref;
77}
78
79/* IDirect3DStateBlock9 Interface follow: */
80static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(LPDIRECT3DSTATEBLOCK9 iface, IDirect3DDevice9** ppDevice) {
81 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
82 IWineD3DDevice *wined3d_device;
83 HRESULT hr;
84 TRACE("(%p) Relay\n", This);
85
86 wined3d_mutex_lock();
87 hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
88 if (SUCCEEDED(hr))
89 {
90 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
91 IWineD3DDevice_Release(wined3d_device);
92 }
93 wined3d_mutex_unlock();
94
95 return hr;
96}
97
98static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
99 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
100 HRESULT hr;
101 TRACE("(%p) Relay\n", This);
102
103 wined3d_mutex_lock();
104 hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
105 wined3d_mutex_unlock();
106
107 return hr;
108}
109
110static HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface) {
111 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
112 HRESULT hr;
113 TRACE("(%p) Relay\n", This);
114
115 wined3d_mutex_lock();
116 hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
117 wined3d_mutex_unlock();
118
119 return hr;
120}
121
122
123static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl =
124{
125 /* IUnknown */
126 IDirect3DStateBlock9Impl_QueryInterface,
127 IDirect3DStateBlock9Impl_AddRef,
128 IDirect3DStateBlock9Impl_Release,
129 /* IDirect3DStateBlock9 */
130 IDirect3DStateBlock9Impl_GetDevice,
131 IDirect3DStateBlock9Impl_Capture,
132 IDirect3DStateBlock9Impl_Apply
133};
134
135
136/* IDirect3DDevice9 IDirect3DStateBlock9 Methods follow: */
137HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface, D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppStateBlock) {
138 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
139 IDirect3DStateBlock9Impl* object;
140 HRESULT hrc = D3D_OK;
141
142 TRACE("(%p) Relay\n", This);
143
144 if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE &&
145 Type != D3DSBT_VERTEXSTATE ) {
146 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
147 return D3DERR_INVALIDCALL;
148 }
149
150 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
151 if (NULL == object) return E_OUTOFMEMORY;
152 object->lpVtbl = &Direct3DStateBlock9_Vtbl;
153 object->ref = 1;
154
155 wined3d_mutex_lock();
156 hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown*)object);
157 wined3d_mutex_unlock();
158
159 if(hrc != D3D_OK){
160 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
161 HeapFree(GetProcessHeap(), 0, object);
162 } else {
163 IDirect3DDevice9Ex_AddRef(iface);
164 object->parentDevice = iface;
165 *ppStateBlock = (IDirect3DStateBlock9*)object;
166 TRACE("(%p) : Created stateblock %p\n", This, object);
167 }
168 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
169 return hrc;
170}
171
172HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
173{
174 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
175 HRESULT hr;
176 TRACE("(%p) Relay\n", This);
177
178 wined3d_mutex_lock();
179 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
180 wined3d_mutex_unlock();
181
182 return hr;
183}
184
185HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **ppSB)
186{
187 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
188 IWineD3DStateBlock *wineD3DStateBlock;
189 IDirect3DStateBlock9Impl *object;
190 HRESULT hr;
191
192 TRACE("(%p) Relay\n", This);
193
194 /* Tell wineD3D to endstateblock before anything else (in case we run out
195 * of memory later and cause locking problems) */
196 wined3d_mutex_lock();
197 hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
198 wined3d_mutex_unlock();
199
200 if (hr!= D3D_OK)
201 {
202 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
203 return hr;
204 }
205 /* allocate a new IDirectD3DStateBlock */
206 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
207 if (!object) return E_OUTOFMEMORY;
208 object->ref = 1;
209 object->lpVtbl = &Direct3DStateBlock9_Vtbl;
210 object->wineD3DStateBlock = wineD3DStateBlock;
211
212 IDirect3DDevice9Ex_AddRef(iface);
213 object->parentDevice = iface;
214 *ppSB=(IDirect3DStateBlock9*)object;
215 TRACE("(%p) Returning *ppSB %p, wineD3DStateBlock %p\n", This, *ppSB, wineD3DStateBlock);
216 return D3D_OK;
217}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette