VirtualBox

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

Last change on this file since 26846 was 25949, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.36 and disable unnecessary fbo state poll

  • 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 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
42
43 if (IsEqualGUID(riid, &IID_IUnknown)
44 || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
45 IDirect3DStateBlock9_AddRef(iface);
46 *ppobj = This;
47 return S_OK;
48 }
49
50 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
51 *ppobj = NULL;
52 return E_NOINTERFACE;
53}
54
55static ULONG WINAPI IDirect3DStateBlock9Impl_AddRef(LPDIRECT3DSTATEBLOCK9 iface) {
56 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
57 ULONG ref = InterlockedIncrement(&This->ref);
58
59 TRACE("%p increasing refcount to %u.\n", iface, ref);
60
61 return ref;
62}
63
64static ULONG WINAPI IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface) {
65 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
66 ULONG ref = InterlockedDecrement(&This->ref);
67
68 TRACE("%p decreasing refcount to %u.\n", iface, ref);
69
70 if (ref == 0) {
71 wined3d_mutex_lock();
72 IWineD3DStateBlock_Release(This->wineD3DStateBlock);
73 wined3d_mutex_unlock();
74
75 IDirect3DDevice9Ex_Release(This->parentDevice);
76 HeapFree(GetProcessHeap(), 0, This);
77 }
78 return ref;
79}
80
81/* IDirect3DStateBlock9 Interface follow: */
82static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device)
83{
84 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
85
86 TRACE("iface %p, device %p.\n", iface, device);
87
88 *device = (IDirect3DDevice9 *)This->parentDevice;
89 IDirect3DDevice9_AddRef(*device);
90
91 TRACE("Returning device %p.\n", *device);
92
93 return D3D_OK;
94}
95
96static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
97 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
98 HRESULT hr;
99
100 TRACE("iface %p.\n", iface);
101
102 wined3d_mutex_lock();
103 hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
104 wined3d_mutex_unlock();
105
106 return hr;
107}
108
109static HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface) {
110 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
111 HRESULT hr;
112
113 TRACE("iface %p.\n", iface);
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("iface %p, type %#x, stateblock %p.\n", iface, Type, ppStateBlock);
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
177 TRACE("iface %p.\n", iface);
178
179 wined3d_mutex_lock();
180 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
181 wined3d_mutex_unlock();
182
183 return hr;
184}
185
186HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **ppSB)
187{
188 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
189 IWineD3DStateBlock *wineD3DStateBlock;
190 IDirect3DStateBlock9Impl *object;
191 HRESULT hr;
192
193 TRACE("iface %p, stateblock %p.\n", iface, ppSB);
194
195 /* Tell wineD3D to endstateblock before anything else (in case we run out
196 * of memory later and cause locking problems) */
197 wined3d_mutex_lock();
198 hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
199 wined3d_mutex_unlock();
200
201 if (hr!= D3D_OK)
202 {
203 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
204 return hr;
205 }
206 /* allocate a new IDirectD3DStateBlock */
207 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
208 if (!object) return E_OUTOFMEMORY;
209 object->ref = 1;
210 object->lpVtbl = &Direct3DStateBlock9_Vtbl;
211 object->wineD3DStateBlock = wineD3DStateBlock;
212
213 IDirect3DDevice9Ex_AddRef(iface);
214 object->parentDevice = iface;
215 *ppSB=(IDirect3DStateBlock9*)object;
216 TRACE("(%p) Returning *ppSB %p, wineD3DStateBlock %p\n", This, *ppSB, wineD3DStateBlock);
217 return D3D_OK;
218}
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