Next try. This time I reverted most of my header changes and just needed to add some...
[reactos.git] / reactos / dll / directx / wine / d3d8 / volume.c
1 /*
2 * IDirect3DVolume8 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DVolume8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DVolume8Impl_QueryInterface(LPDIRECT3DVOLUME8 iface, REFIID riid, LPVOID *ppobj) {
28 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
29
30 if (IsEqualGUID(riid, &IID_IUnknown)
31 || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
32 IUnknown_AddRef(iface);
33 *ppobj = This;
34 return S_OK;
35 }
36
37 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
38 *ppobj = NULL;
39 return E_NOINTERFACE;
40 }
41
42 static ULONG WINAPI IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface) {
43 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
44
45 TRACE("(%p)\n", This);
46
47 if (This->forwardReference) {
48 /* Forward to the containerParent */
49 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
50 return IUnknown_AddRef(This->forwardReference);
51 } else {
52 /* No container, handle our own refcounting */
53 ULONG ref = InterlockedIncrement(&This->ref);
54 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
55 return ref;
56 }
57 }
58
59 static ULONG WINAPI IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface) {
60 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
61
62 TRACE("(%p)\n", This);
63
64 if (This->forwardReference) {
65 /* Forward to the containerParent */
66 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
67 return IUnknown_Release(This->forwardReference);
68 }
69 else {
70 /* No container, handle our own refcounting */
71 ULONG ref = InterlockedDecrement(&This->ref);
72 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
73
74 if (ref == 0) {
75 wined3d_mutex_lock();
76 IWineD3DVolume_Release(This->wineD3DVolume);
77 wined3d_mutex_unlock();
78
79 HeapFree(GetProcessHeap(), 0, This);
80 }
81
82 return ref;
83 }
84 }
85
86 /* IDirect3DVolume8 Interface follow: */
87 static HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface, IDirect3DDevice8 **ppDevice) {
88 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
89 IWineD3DDevice *myDevice = NULL;
90
91 wined3d_mutex_lock();
92 IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
93 IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
94 IWineD3DDevice_Release(myDevice);
95 wined3d_mutex_unlock();
96
97 return D3D_OK;
98 }
99
100 static HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
101 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
102 HRESULT hr;
103 TRACE("(%p) Relay\n", This);
104
105 wined3d_mutex_lock();
106 hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
107 wined3d_mutex_unlock();
108
109 return hr;
110 }
111
112 static HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, void *pData, DWORD* pSizeOfData) {
113 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
114 HRESULT hr;
115 TRACE("(%p) Relay\n", This);
116
117 wined3d_mutex_lock();
118 hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
119 wined3d_mutex_unlock();
120
121 return hr;
122 }
123
124 static HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid) {
125 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
126 HRESULT hr;
127 TRACE("(%p) Relay\n", This);
128
129 wined3d_mutex_lock();
130 hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
131 wined3d_mutex_unlock();
132
133 return hr;
134 }
135
136 static HRESULT WINAPI IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface, REFIID riid, void **ppContainer) {
137 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
138 HRESULT res;
139
140 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
141
142 if (!This->container) return E_NOINTERFACE;
143
144 if (!ppContainer) {
145 ERR("Called without a valid ppContainer.\n");
146 }
147
148 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
149
150 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
151
152 return res;
153 }
154
155 static HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface, D3DVOLUME_DESC *pDesc) {
156 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
157 HRESULT hr;
158 WINED3DVOLUME_DESC wined3ddesc;
159
160 TRACE("(%p) Relay\n", This);
161
162 wined3d_mutex_lock();
163 hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
164 wined3d_mutex_unlock();
165
166 if (SUCCEEDED(hr))
167 {
168 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
169 pDesc->Type = wined3ddesc.Type;
170 pDesc->Usage = wined3ddesc.Usage;
171 pDesc->Pool = wined3ddesc.Pool;
172 pDesc->Size = wined3ddesc.Size;
173 pDesc->Width = wined3ddesc.Width;
174 pDesc->Height = wined3ddesc.Height;
175 pDesc->Depth = wined3ddesc.Depth;
176 }
177
178 return hr;
179 }
180
181 static HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox, DWORD Flags) {
182 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
183 HRESULT hr;
184 TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
185
186 wined3d_mutex_lock();
187 hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
188 wined3d_mutex_unlock();
189
190 return hr;
191 }
192
193 static HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) {
194 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
195 HRESULT hr;
196 TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
197
198 wined3d_mutex_lock();
199 hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
200 wined3d_mutex_unlock();
201
202 return hr;
203 }
204
205 const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
206 {
207 /* IUnknown */
208 IDirect3DVolume8Impl_QueryInterface,
209 IDirect3DVolume8Impl_AddRef,
210 IDirect3DVolume8Impl_Release,
211 /* IDirect3DVolume8 */
212 IDirect3DVolume8Impl_GetDevice,
213 IDirect3DVolume8Impl_SetPrivateData,
214 IDirect3DVolume8Impl_GetPrivateData,
215 IDirect3DVolume8Impl_FreePrivateData,
216 IDirect3DVolume8Impl_GetContainer,
217 IDirect3DVolume8Impl_GetDesc,
218 IDirect3DVolume8Impl_LockBox,
219 IDirect3DVolume8Impl_UnlockBox
220 };
221
222 ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume) {
223 IDirect3DVolume8Impl* volumeParent;
224
225 IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
226 /* GetParent's AddRef was forwarded to an object in destruction.
227 * Releasing it here again would cause an endless recursion. */
228 volumeParent->forwardReference = NULL;
229 return IDirect3DVolume8_Release((IDirect3DVolume8*) volumeParent);
230 }