crypt32: Add basic flags tests flags for CertFindCRLInStore with find type CRL_FIND_I...
[wine] / dlls / d3d9 / volume.c
1 /*
2  * IDirect3DVolume9 implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  *                     Raphael Junqueira
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DVolume9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
30
31     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
32
33     if (IsEqualGUID(riid, &IID_IUnknown)
34         || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
35         IDirect3DVolume9_AddRef(iface);
36         *ppobj = This;
37         return S_OK;
38     }
39
40     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41     *ppobj = NULL;
42     return E_NOINTERFACE;
43 }
44
45 static ULONG WINAPI IDirect3DVolume9Impl_AddRef(LPDIRECT3DVOLUME9 iface) {
46     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
47
48     TRACE("iface %p.\n", iface);
49
50     if (This->forwardReference) {
51         /* Forward refcounting */
52         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
53         return IUnknown_AddRef(This->forwardReference);
54     } else {
55         /* No container, handle our own refcounting */
56         ULONG ref = InterlockedIncrement(&This->ref);
57
58         TRACE("%p increasing refcount to %u.\n", iface, ref);
59
60         if (ref == 1)
61         {
62             wined3d_mutex_lock();
63             IWineD3DVolume_AddRef(This->wineD3DVolume);
64             wined3d_mutex_unlock();
65         }
66
67         return ref;
68     }
69 }
70
71 static ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
72     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
73
74     TRACE("iface %p.\n", iface);
75
76     if (This->forwardReference) {
77         /* Forward refcounting */
78         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
79         return IUnknown_Release(This->forwardReference);
80     } else {
81         /* No container, handle our own refcounting */
82         ULONG ref = InterlockedDecrement(&This->ref);
83
84         TRACE("%p decreasing refcount to %u.\n", iface, ref);
85
86         if (ref == 0) {
87             wined3d_mutex_lock();
88             IWineD3DVolume_Release(This->wineD3DVolume);
89             wined3d_mutex_unlock();
90         }
91
92         return ref;
93     }
94 }
95
96 /* IDirect3DVolume9 Interface follow: */
97 static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
98     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
99     IWineD3DDevice       *myDevice = NULL;
100
101     TRACE("iface %p, device %p.\n", iface, ppDevice);
102
103     wined3d_mutex_lock();
104
105     IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
106     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
107     IWineD3DDevice_Release(myDevice);
108
109     wined3d_mutex_unlock();
110
111     return D3D_OK;
112 }
113
114 static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
115     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
116     HRESULT hr;
117
118     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
119             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
120
121     wined3d_mutex_lock();
122
123     hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
124
125     wined3d_mutex_unlock();
126
127     return hr;
128 }
129
130 static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID  refguid, void* pData, DWORD* pSizeOfData) {
131     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
132     HRESULT hr;
133
134     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
135             iface, debugstr_guid(refguid), pData, pSizeOfData);
136
137     wined3d_mutex_lock();
138
139     hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
140
141     wined3d_mutex_unlock();
142
143     return hr;
144 }
145
146 static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
147     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
148     HRESULT hr;
149
150     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
151
152     wined3d_mutex_lock();
153
154     hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
155
156     wined3d_mutex_unlock();
157
158     return hr;
159 }
160
161 static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
162     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
163     HRESULT res;
164
165     TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
166
167     if (!This->container) return E_NOINTERFACE;
168
169     if (!ppContainer) {
170         ERR("Called without a valid ppContainer.\n");
171     }
172
173     res = IUnknown_QueryInterface(This->container, riid, ppContainer);
174
175     TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
176
177     return res;
178 }
179
180 static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
181     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
182     WINED3DVOLUME_DESC     wined3ddesc;
183     HRESULT hr;
184
185     TRACE("iface %p, desc %p.\n", iface, pDesc);
186
187     wined3d_mutex_lock();
188
189     hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
190
191     wined3d_mutex_unlock();
192
193     if (SUCCEEDED(hr))
194     {
195         pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
196         pDesc->Type = wined3ddesc.Type;
197         pDesc->Usage = wined3ddesc.Usage;
198         pDesc->Pool = wined3ddesc.Pool;
199         pDesc->Width = wined3ddesc.Width;
200         pDesc->Height = wined3ddesc.Height;
201         pDesc->Depth = wined3ddesc.Depth;
202     }
203
204     return hr;
205 }
206
207 static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
208     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
209     HRESULT hr;
210
211     TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
212             iface, pLockedVolume, pBox, Flags);
213
214     wined3d_mutex_lock();
215
216     hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume,
217             (const WINED3DBOX *)pBox, Flags);
218
219     wined3d_mutex_unlock();
220
221     return hr;
222 }
223
224 static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
225     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
226     HRESULT hr;
227
228     TRACE("iface %p.\n", iface);
229
230     wined3d_mutex_lock();
231
232     hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
233
234     wined3d_mutex_unlock();
235
236     return hr;
237 }
238
239 static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
240 {
241     /* IUnknown */
242     IDirect3DVolume9Impl_QueryInterface,
243     IDirect3DVolume9Impl_AddRef,
244     IDirect3DVolume9Impl_Release,
245     /* IDirect3DVolume9 */
246     IDirect3DVolume9Impl_GetDevice,
247     IDirect3DVolume9Impl_SetPrivateData,
248     IDirect3DVolume9Impl_GetPrivateData,
249     IDirect3DVolume9Impl_FreePrivateData,
250     IDirect3DVolume9Impl_GetContainer,
251     IDirect3DVolume9Impl_GetDesc,
252     IDirect3DVolume9Impl_LockBox,
253     IDirect3DVolume9Impl_UnlockBox
254 };
255
256 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
257 {
258     HeapFree(GetProcessHeap(), 0, parent);
259 }
260
261 static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
262 {
263     volume_wined3d_object_destroyed,
264 };
265
266 HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
267         UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool)
268 {
269     HRESULT hr;
270
271     volume->lpVtbl = &Direct3DVolume9_Vtbl;
272     volume->ref = 1;
273
274     hr = IWineD3DDevice_CreateVolume(device->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
275             format, pool, &volume->wineD3DVolume, (IUnknown *)volume, &d3d9_volume_wined3d_parent_ops);
276     if (FAILED(hr))
277     {
278         WARN("Failed to create wined3d volume, hr %#x.\n", hr);
279         return hr;
280     }
281
282     return D3D_OK;
283 }