VirtualBox

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

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

opengl: update wine to 1.1.21, add d3d9.dll to build list

  • Property svn:eol-style set to native
File size: 7.5 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 EnterCriticalSection(&d3d9_cs);
70 IWineD3DStateBlock_Release(This->wineD3DStateBlock);
71 LeaveCriticalSection(&d3d9_cs);
72 IDirect3DDevice9Ex_Release(This->parentDevice);
73 HeapFree(GetProcessHeap(), 0, This);
74 }
75 return ref;
76}
77
78/* IDirect3DStateBlock9 Interface follow: */
79static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(LPDIRECT3DSTATEBLOCK9 iface, IDirect3DDevice9** ppDevice) {
80 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
81 IWineD3DDevice *wined3d_device;
82 HRESULT hr;
83 TRACE("(%p) Relay\n", This);
84
85 EnterCriticalSection(&d3d9_cs);
86 hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
87 if (SUCCEEDED(hr))
88 {
89 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
90 IWineD3DDevice_Release(wined3d_device);
91 }
92 LeaveCriticalSection(&d3d9_cs);
93 return hr;
94}
95
96static HRESULT WINAPI IDirect3DStateBlock9Impl_Capture(LPDIRECT3DSTATEBLOCK9 iface) {
97 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
98 HRESULT hr;
99 TRACE("(%p) Relay\n", This);
100
101 EnterCriticalSection(&d3d9_cs);
102 hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
103 LeaveCriticalSection(&d3d9_cs);
104 return hr;
105}
106
107static HRESULT WINAPI IDirect3DStateBlock9Impl_Apply(LPDIRECT3DSTATEBLOCK9 iface) {
108 IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
109 HRESULT hr;
110 TRACE("(%p) Relay\n", This);
111
112 EnterCriticalSection(&d3d9_cs);
113 hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
114 LeaveCriticalSection(&d3d9_cs);
115 return hr;
116}
117
118
119static const IDirect3DStateBlock9Vtbl Direct3DStateBlock9_Vtbl =
120{
121 /* IUnknown */
122 IDirect3DStateBlock9Impl_QueryInterface,
123 IDirect3DStateBlock9Impl_AddRef,
124 IDirect3DStateBlock9Impl_Release,
125 /* IDirect3DStateBlock9 */
126 IDirect3DStateBlock9Impl_GetDevice,
127 IDirect3DStateBlock9Impl_Capture,
128 IDirect3DStateBlock9Impl_Apply
129};
130
131
132/* IDirect3DDevice9 IDirect3DStateBlock9 Methods follow: */
133HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface, D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppStateBlock) {
134 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
135 IDirect3DStateBlock9Impl* object;
136 HRESULT hrc = D3D_OK;
137
138 TRACE("(%p) Relay\n", This);
139
140 if(Type != D3DSBT_ALL && Type != D3DSBT_PIXELSTATE &&
141 Type != D3DSBT_VERTEXSTATE ) {
142 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL\n");
143 return D3DERR_INVALIDCALL;
144 }
145
146 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
147 if (NULL == object) return E_OUTOFMEMORY;
148 object->lpVtbl = &Direct3DStateBlock9_Vtbl;
149 object->ref = 1;
150
151 EnterCriticalSection(&d3d9_cs);
152 hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown*)object);
153 LeaveCriticalSection(&d3d9_cs);
154 if(hrc != D3D_OK){
155 FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
156 HeapFree(GetProcessHeap(), 0, object);
157 } else {
158 IDirect3DDevice9Ex_AddRef(iface);
159 object->parentDevice = iface;
160 *ppStateBlock = (IDirect3DStateBlock9*)object;
161 TRACE("(%p) : Created stateblock %p\n", This, object);
162 }
163 TRACE("(%p) returning token (ptr to stateblock) of %p\n", This, object);
164 return hrc;
165}
166
167HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(LPDIRECT3DDEVICE9EX iface) {
168 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
169 HRESULT hr;
170 TRACE("(%p) Relay\n", This);
171
172 EnterCriticalSection(&d3d9_cs);
173 hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
174 LeaveCriticalSection(&d3d9_cs);
175 return hr;
176}
177
178HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9EX iface, IDirect3DStateBlock9** ppSB) {
179 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
180 HRESULT hr;
181 IWineD3DStateBlock* wineD3DStateBlock;
182 IDirect3DStateBlock9Impl* object;
183
184 TRACE("(%p) Relay\n", This);
185
186 /* Tell wineD3D to endstateblock before anything else (in case we run out
187 * of memory later and cause locking problems)
188 */
189 EnterCriticalSection(&d3d9_cs);
190 hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
191 LeaveCriticalSection(&d3d9_cs);
192 if(hr!= D3D_OK){
193 WARN("IWineD3DDevice_EndStateBlock returned an error\n");
194 return hr;
195 }
196 /* allocate a new IDirectD3DStateBlock */
197 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock9Impl));
198 if (!object) return E_OUTOFMEMORY;
199 object->ref = 1;
200 object->lpVtbl = &Direct3DStateBlock9_Vtbl;
201 object->wineD3DStateBlock = wineD3DStateBlock;
202
203 IDirect3DDevice9Ex_AddRef(iface);
204 object->parentDevice = iface;
205 *ppSB=(IDirect3DStateBlock9*)object;
206 TRACE("(%p) Returning *ppSB %p, wineD3DStateBlock %p\n", This, *ppSB, wineD3DStateBlock);
207 return D3D_OK;
208}
Note: See TracBrowser for help on using the repository browser.

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