gdi32: Recompute the background masks on every use to support PALETTEINDEX colors.
[wine/multimedia.git] / dlls / d3d8 / volume.c
blob505e17b119a18687779cdb28ee90ff3a3e087f64
1 /*
2 * IDirect3DVolume8 implementation
4 * Copyright 2005 Oliver Stieber
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.
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.
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
21 #include "config.h"
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 static inline IDirect3DVolume8Impl *impl_from_IDirect3DVolume8(IDirect3DVolume8 *iface)
28 return CONTAINING_RECORD(iface, IDirect3DVolume8Impl, IDirect3DVolume8_iface);
31 static HRESULT WINAPI IDirect3DVolume8Impl_QueryInterface(IDirect3DVolume8 *iface, REFIID riid,
32 void **ppobj)
34 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
36 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
40 IUnknown_AddRef(iface);
41 *ppobj = This;
42 return S_OK;
45 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
46 *ppobj = NULL;
47 return E_NOINTERFACE;
50 static ULONG WINAPI IDirect3DVolume8Impl_AddRef(IDirect3DVolume8 *iface)
52 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
54 TRACE("iface %p.\n", iface);
56 if (This->forwardReference) {
57 /* Forward to the containerParent */
58 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
59 return IUnknown_AddRef(This->forwardReference);
60 } else {
61 /* No container, handle our own refcounting */
62 ULONG ref = InterlockedIncrement(&This->ref);
64 TRACE("%p increasing refcount to %u.\n", iface, ref);
66 if (ref == 1)
68 wined3d_mutex_lock();
69 wined3d_volume_incref(This->wined3d_volume);
70 wined3d_mutex_unlock();
73 return ref;
77 static ULONG WINAPI IDirect3DVolume8Impl_Release(IDirect3DVolume8 *iface)
79 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
81 TRACE("iface %p.\n", iface);
83 if (This->forwardReference) {
84 /* Forward to the containerParent */
85 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
86 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 IDirect3DVolume8Impl_GetDevice(IDirect3DVolume8 *iface,
105 IDirect3DDevice8 **device)
107 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
108 IDirect3DResource8 *resource;
109 HRESULT hr;
111 TRACE("iface %p, device %p.\n", iface, device);
113 hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
114 if (SUCCEEDED(hr))
116 hr = IDirect3DResource8_GetDevice(resource, device);
117 IDirect3DResource8_Release(resource);
119 TRACE("Returning device %p.\n", *device);
122 return hr;
125 static HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(IDirect3DVolume8 *iface, REFGUID refguid,
126 const void *pData, DWORD SizeOfData, DWORD Flags)
128 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(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 IDirect3DVolume8Impl_GetPrivateData(IDirect3DVolume8 *iface, REFGUID refguid,
144 void *pData, DWORD *pSizeOfData)
146 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(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 IDirect3DVolume8Impl_FreePrivateData(IDirect3DVolume8 *iface, REFGUID refguid)
163 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(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 IDirect3DVolume8Impl_GetContainer(IDirect3DVolume8 *iface, REFIID riid,
178 void **ppContainer)
180 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
181 HRESULT res;
183 TRACE("iface %p, riid %s, container %p.\n",
184 iface, debugstr_guid(riid), ppContainer);
186 if (!This->container) return E_NOINTERFACE;
188 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
190 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
192 return res;
195 static HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(IDirect3DVolume8 *iface, D3DVOLUME_DESC *desc)
197 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
198 struct wined3d_resource_desc wined3d_desc;
199 struct wined3d_resource *wined3d_resource;
201 TRACE("iface %p, desc %p.\n", iface, desc);
203 wined3d_mutex_lock();
204 wined3d_resource = wined3d_volume_get_resource(This->wined3d_volume);
205 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
206 wined3d_mutex_unlock();
208 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
209 desc->Type = wined3d_desc.resource_type;
210 desc->Usage = wined3d_desc.usage;
211 desc->Pool = wined3d_desc.pool;
212 desc->Size = wined3d_desc.size;
213 desc->Width = wined3d_desc.width;
214 desc->Height = wined3d_desc.height;
215 desc->Depth = wined3d_desc.depth;
217 return D3D_OK;
220 static HRESULT WINAPI IDirect3DVolume8Impl_LockBox(IDirect3DVolume8 *iface,
221 D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags)
223 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
224 HRESULT hr;
226 TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
227 iface, pLockedVolume, pBox, Flags);
229 wined3d_mutex_lock();
230 hr = wined3d_volume_map(This->wined3d_volume, (struct wined3d_mapped_box *)pLockedVolume,
231 (const struct wined3d_box *)pBox, Flags);
232 wined3d_mutex_unlock();
234 return hr;
237 static HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(IDirect3DVolume8 *iface)
239 IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
240 HRESULT hr;
242 TRACE("iface %p.\n", iface);
244 wined3d_mutex_lock();
245 hr = wined3d_volume_unmap(This->wined3d_volume);
246 wined3d_mutex_unlock();
248 return hr;
251 static const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
253 /* IUnknown */
254 IDirect3DVolume8Impl_QueryInterface,
255 IDirect3DVolume8Impl_AddRef,
256 IDirect3DVolume8Impl_Release,
257 /* IDirect3DVolume8 */
258 IDirect3DVolume8Impl_GetDevice,
259 IDirect3DVolume8Impl_SetPrivateData,
260 IDirect3DVolume8Impl_GetPrivateData,
261 IDirect3DVolume8Impl_FreePrivateData,
262 IDirect3DVolume8Impl_GetContainer,
263 IDirect3DVolume8Impl_GetDesc,
264 IDirect3DVolume8Impl_LockBox,
265 IDirect3DVolume8Impl_UnlockBox
268 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
270 HeapFree(GetProcessHeap(), 0, parent);
273 static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
275 volume_wined3d_object_destroyed,
278 HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
279 UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool)
281 HRESULT hr;
283 volume->IDirect3DVolume8_iface.lpVtbl = &Direct3DVolume8_Vtbl;
284 volume->ref = 1;
286 hr = wined3d_volume_create(device->wined3d_device, width, height, depth, usage,
287 format, pool, volume, &d3d8_volume_wined3d_parent_ops, &volume->wined3d_volume);
288 if (FAILED(hr))
290 WARN("Failed to create wined3d volume, hr %#x.\n", hr);
291 return hr;
294 return D3D_OK;