msvcrt: Added _sscanf_l implementation.
[wine] / dlls / 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     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
31
32     if (IsEqualGUID(riid, &IID_IUnknown)
33         || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
34         IUnknown_AddRef(iface);
35         *ppobj = This;
36         return S_OK;
37     }
38
39     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
40     *ppobj = NULL;
41     return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface) {
45     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
46
47     TRACE("iface %p.\n", iface);
48
49     if (This->forwardReference) {
50         /* Forward to the containerParent */
51         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
52         return IUnknown_AddRef(This->forwardReference);
53     } else {
54         /* No container, handle our own refcounting */
55         ULONG ref = InterlockedIncrement(&This->ref);
56
57         TRACE("%p increasing refcount to %u.\n", iface, ref);
58
59         if (ref == 1)
60         {
61             wined3d_mutex_lock();
62             IWineD3DVolume_AddRef(This->wineD3DVolume);
63             wined3d_mutex_unlock();
64         }
65
66         return ref;
67     }
68 }
69
70 static ULONG WINAPI IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface) {
71     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
72
73     TRACE("iface %p.\n", iface);
74
75     if (This->forwardReference) {
76         /* Forward to the containerParent */
77         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
78         return IUnknown_Release(This->forwardReference);
79     }
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 /* IDirect3DVolume8 Interface follow: */
97 static HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(IDirect3DVolume8 *iface, IDirect3DDevice8 **device)
98 {
99     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
100     IDirect3DResource8 *resource;
101     HRESULT hr;
102
103     TRACE("iface %p, device %p.\n", iface, device);
104
105     hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
106     if (SUCCEEDED(hr))
107     {
108         hr = IDirect3DResource8_GetDevice(resource, device);
109         IDirect3DResource8_Release(resource);
110
111         TRACE("Returning device %p.\n", *device);
112     }
113
114     return hr;
115 }
116
117 static HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
118     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
119     HRESULT hr;
120
121     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
122             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
123
124     wined3d_mutex_lock();
125     hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
126     wined3d_mutex_unlock();
127
128     return hr;
129 }
130
131 static HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID  refguid, void *pData, DWORD* pSizeOfData) {
132     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
133     HRESULT hr;
134
135     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
136             iface, debugstr_guid(refguid), pData, pSizeOfData);
137
138     wined3d_mutex_lock();
139     hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
140     wined3d_mutex_unlock();
141
142     return hr;
143 }
144
145 static HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid) {
146     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
147     HRESULT hr;
148
149     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
150
151     wined3d_mutex_lock();
152     hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
153     wined3d_mutex_unlock();
154
155     return hr;
156 }
157
158 static HRESULT WINAPI IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface, REFIID riid, void **ppContainer) {
159     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
160     HRESULT res;
161
162     TRACE("iface %p, riid %s, container %p.\n",
163             iface, debugstr_guid(riid), ppContainer);
164
165     if (!This->container) return E_NOINTERFACE;
166
167     if (!ppContainer) {
168         ERR("Called without a valid ppContainer.\n");
169     }
170
171     res = IUnknown_QueryInterface(This->container, riid, ppContainer);
172
173     TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
174
175     return res;
176 }
177
178 static HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface, D3DVOLUME_DESC *pDesc) {
179     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
180     HRESULT hr;
181     WINED3DVOLUME_DESC     wined3ddesc;
182
183     TRACE("iface %p, desc %p.\n", iface, pDesc);
184
185     wined3d_mutex_lock();
186     hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
187     wined3d_mutex_unlock();
188
189     if (SUCCEEDED(hr))
190     {
191         pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
192         pDesc->Type = wined3ddesc.Type;
193         pDesc->Usage = wined3ddesc.Usage;
194         pDesc->Pool = wined3ddesc.Pool;
195         pDesc->Size = wined3ddesc.Size;
196         pDesc->Width = wined3ddesc.Width;
197         pDesc->Height = wined3ddesc.Height;
198         pDesc->Depth = wined3ddesc.Depth;
199     }
200
201     return hr;
202 }
203
204 static HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox, DWORD Flags) {
205     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
206     HRESULT hr;
207
208     TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
209             iface, pLockedVolume, pBox, Flags);
210
211     wined3d_mutex_lock();
212     hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
213     wined3d_mutex_unlock();
214
215     return hr;
216 }
217
218 static HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) {
219     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
220     HRESULT hr;
221
222     TRACE("iface %p.\n", iface);
223
224     wined3d_mutex_lock();
225     hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
226     wined3d_mutex_unlock();
227
228     return hr;
229 }
230
231 static const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
232 {
233     /* IUnknown */
234     IDirect3DVolume8Impl_QueryInterface,
235     IDirect3DVolume8Impl_AddRef,
236     IDirect3DVolume8Impl_Release,
237     /* IDirect3DVolume8 */
238     IDirect3DVolume8Impl_GetDevice,
239     IDirect3DVolume8Impl_SetPrivateData,
240     IDirect3DVolume8Impl_GetPrivateData,
241     IDirect3DVolume8Impl_FreePrivateData,
242     IDirect3DVolume8Impl_GetContainer,
243     IDirect3DVolume8Impl_GetDesc,
244     IDirect3DVolume8Impl_LockBox,
245     IDirect3DVolume8Impl_UnlockBox
246 };
247
248 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
249 {
250     HeapFree(GetProcessHeap(), 0, parent);
251 }
252
253 static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
254 {
255     volume_wined3d_object_destroyed,
256 };
257
258 HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
259         UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool)
260 {
261     HRESULT hr;
262
263     volume->lpVtbl = &Direct3DVolume8_Vtbl;
264     volume->ref = 1;
265
266     hr = IWineD3DDevice_CreateVolume(device->WineD3DDevice, width, height, depth, usage,
267             format, pool, &volume->wineD3DVolume, (IUnknown *)volume, &d3d8_volume_wined3d_parent_ops);
268     if (FAILED(hr))
269     {
270         WARN("Failed to create wined3d volume, hr %#x.\n", hr);
271         return hr;
272     }
273
274     return D3D_OK;
275 }