d3d9: Return D3DERR_INVALIDCALL when IDirect3DCubeTexture9::GetLevelDesc is called...
[wine/multimedia.git] / dlls / d3d9 / volume.c
blob3d5e86b78df6333ee064482553d16490e24f8f0d
1 /*
2 * IDirect3DVolume9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Raphael Junqueira
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.
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.
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
22 #include "config.h"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 static inline IDirect3DVolume9Impl *impl_from_IDirect3DVolume9(IDirect3DVolume9 *iface)
29 return CONTAINING_RECORD(iface, IDirect3DVolume9Impl, IDirect3DVolume9_iface);
32 static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(IDirect3DVolume9 *iface, REFIID riid,
33 void **ppobj)
35 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
37 if (IsEqualGUID(riid, &IID_IDirect3DVolume9)
38 || IsEqualGUID(riid, &IID_IUnknown))
40 IDirect3DVolume9_AddRef(iface);
41 *ppobj = iface;
42 return S_OK;
45 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
47 *ppobj = NULL;
48 return E_NOINTERFACE;
51 static ULONG WINAPI IDirect3DVolume9Impl_AddRef(IDirect3DVolume9 *iface)
53 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
55 TRACE("iface %p.\n", iface);
57 if (This->forwardReference) {
58 /* Forward refcounting */
59 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
60 return IUnknown_AddRef(This->forwardReference);
61 } else {
62 /* No container, handle our own refcounting */
63 ULONG ref = InterlockedIncrement(&This->ref);
65 TRACE("%p increasing refcount to %u.\n", iface, ref);
67 if (ref == 1)
69 wined3d_mutex_lock();
70 wined3d_volume_incref(This->wined3d_volume);
71 wined3d_mutex_unlock();
74 return ref;
78 static ULONG WINAPI IDirect3DVolume9Impl_Release(IDirect3DVolume9 *iface)
80 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
82 TRACE("iface %p.\n", iface);
84 if (This->forwardReference) {
85 /* Forward refcounting */
86 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
87 return IUnknown_Release(This->forwardReference);
88 } else {
89 /* No container, handle our own refcounting */
90 ULONG ref = InterlockedDecrement(&This->ref);
92 TRACE("%p decreasing refcount to %u.\n", iface, ref);
94 if (ref == 0) {
95 wined3d_mutex_lock();
96 wined3d_volume_decref(This->wined3d_volume);
97 wined3d_mutex_unlock();
100 return ref;
104 static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(IDirect3DVolume9 *iface,
105 IDirect3DDevice9 **device)
107 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
108 IDirect3DResource9 *resource;
109 HRESULT hr;
111 TRACE("iface %p, device %p.\n", iface, device);
113 hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
114 if (SUCCEEDED(hr))
116 hr = IDirect3DResource9_GetDevice(resource, device);
117 IDirect3DResource9_Release(resource);
119 TRACE("Returning device %p.\n", *device);
122 return hr;
125 static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(IDirect3DVolume9 *iface, REFGUID refguid,
126 const void *pData, DWORD SizeOfData, DWORD Flags)
128 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
129 struct wined3d_resource *resource;
130 HRESULT hr;
132 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
133 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
135 wined3d_mutex_lock();
136 resource = wined3d_volume_get_resource(This->wined3d_volume);
137 hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
138 wined3d_mutex_unlock();
140 return hr;
143 static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(IDirect3DVolume9 *iface, REFGUID refguid,
144 void *pData, DWORD *pSizeOfData)
146 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
147 struct wined3d_resource *resource;
148 HRESULT hr;
150 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
151 iface, debugstr_guid(refguid), pData, pSizeOfData);
153 wined3d_mutex_lock();
154 resource = wined3d_volume_get_resource(This->wined3d_volume);
155 hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
156 wined3d_mutex_unlock();
158 return hr;
161 static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(IDirect3DVolume9 *iface, REFGUID refguid)
163 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
164 struct wined3d_resource *resource;
165 HRESULT hr;
167 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
169 wined3d_mutex_lock();
170 resource = wined3d_volume_get_resource(This->wined3d_volume);
171 hr = wined3d_resource_free_private_data(resource, refguid);
172 wined3d_mutex_unlock();
174 return hr;
177 static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(IDirect3DVolume9 *iface, REFIID riid,
178 void **ppContainer)
180 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
181 HRESULT res;
183 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
185 if (!This->container) return E_NOINTERFACE;
187 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
189 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
191 return res;
194 static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(IDirect3DVolume9 *iface, D3DVOLUME_DESC *desc)
196 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
197 struct wined3d_resource_desc wined3d_desc;
198 struct wined3d_resource *wined3d_resource;
200 TRACE("iface %p, desc %p.\n", iface, desc);
202 wined3d_mutex_lock();
203 wined3d_resource = wined3d_volume_get_resource(This->wined3d_volume);
204 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
205 wined3d_mutex_unlock();
207 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
208 desc->Type = wined3d_desc.resource_type;
209 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
210 desc->Pool = wined3d_desc.pool;
211 desc->Width = wined3d_desc.width;
212 desc->Height = wined3d_desc.height;
213 desc->Depth = wined3d_desc.depth;
215 return D3D_OK;
218 static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(IDirect3DVolume9 *iface,
219 D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
221 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
222 struct wined3d_map_desc map_desc;
223 HRESULT hr;
225 TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
226 iface, locked_box, box, flags);
228 wined3d_mutex_lock();
229 hr = wined3d_volume_map(This->wined3d_volume, &map_desc, (const struct wined3d_box *)box, flags);
230 wined3d_mutex_unlock();
232 locked_box->RowPitch = map_desc.row_pitch;
233 locked_box->SlicePitch = map_desc.slice_pitch;
234 locked_box->pBits = map_desc.data;
236 return hr;
239 static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(IDirect3DVolume9 *iface)
241 IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
242 HRESULT hr;
244 TRACE("iface %p.\n", iface);
246 wined3d_mutex_lock();
247 hr = wined3d_volume_unmap(This->wined3d_volume);
248 wined3d_mutex_unlock();
250 return hr;
253 static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
255 /* IUnknown */
256 IDirect3DVolume9Impl_QueryInterface,
257 IDirect3DVolume9Impl_AddRef,
258 IDirect3DVolume9Impl_Release,
259 /* IDirect3DVolume9 */
260 IDirect3DVolume9Impl_GetDevice,
261 IDirect3DVolume9Impl_SetPrivateData,
262 IDirect3DVolume9Impl_GetPrivateData,
263 IDirect3DVolume9Impl_FreePrivateData,
264 IDirect3DVolume9Impl_GetContainer,
265 IDirect3DVolume9Impl_GetDesc,
266 IDirect3DVolume9Impl_LockBox,
267 IDirect3DVolume9Impl_UnlockBox
270 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
272 HeapFree(GetProcessHeap(), 0, parent);
275 static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
277 volume_wined3d_object_destroyed,
280 HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
281 UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool)
283 HRESULT hr;
285 volume->IDirect3DVolume9_iface.lpVtbl = &Direct3DVolume9_Vtbl;
286 volume->ref = 1;
288 hr = wined3d_volume_create(device->wined3d_device, width, height, depth, usage & WINED3DUSAGE_MASK,
289 format, pool, volume, &d3d9_volume_wined3d_parent_ops, &volume->wined3d_volume);
290 if (FAILED(hr))
292 WARN("Failed to create wined3d volume, hr %#x.\n", hr);
293 return hr;
296 return D3D_OK;