2 * IDirect3DVolume9 implementation
4 * Copyright 2002-2005 Jason Edmeades
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
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
27 static inline struct d3d9_volume
*impl_from_IDirect3DVolume9(IDirect3DVolume9
*iface
)
29 return CONTAINING_RECORD(iface
, struct d3d9_volume
, IDirect3DVolume9_iface
);
32 static HRESULT WINAPI
d3d9_volume_QueryInterface(IDirect3DVolume9
*iface
, REFIID riid
, void **out
)
34 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
36 if (IsEqualGUID(riid
, &IID_IDirect3DVolume9
)
37 || IsEqualGUID(riid
, &IID_IUnknown
))
39 IDirect3DVolume9_AddRef(iface
);
44 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
50 static ULONG WINAPI
d3d9_volume_AddRef(IDirect3DVolume9
*iface
)
52 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
55 TRACE("iface %p.\n", iface
);
57 if (volume
->forwardReference
)
59 TRACE("Forwarding to %p.\n", volume
->forwardReference
);
60 return IUnknown_AddRef(volume
->forwardReference
);
63 refcount
= InterlockedIncrement(&volume
->resource
.refcount
);
64 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
69 wined3d_volume_incref(volume
->wined3d_volume
);
70 wined3d_mutex_unlock();
76 static ULONG WINAPI
d3d9_volume_Release(IDirect3DVolume9
*iface
)
78 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
81 TRACE("iface %p.\n", iface
);
83 if (volume
->forwardReference
)
85 TRACE("Forwarding to %p.\n", volume
->forwardReference
);
86 return IUnknown_Release(volume
->forwardReference
);
89 refcount
= InterlockedDecrement(&volume
->resource
.refcount
);
90 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
95 wined3d_volume_decref(volume
->wined3d_volume
);
96 wined3d_mutex_unlock();
102 static HRESULT WINAPI
d3d9_volume_GetDevice(IDirect3DVolume9
*iface
, IDirect3DDevice9
**device
)
104 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
105 IDirect3DResource9
*resource
;
108 TRACE("iface %p, device %p.\n", iface
, device
);
110 hr
= IUnknown_QueryInterface(volume
->forwardReference
, &IID_IDirect3DResource9
, (void **)&resource
);
113 hr
= IDirect3DResource9_GetDevice(resource
, device
);
114 IDirect3DResource9_Release(resource
);
116 TRACE("Returning device %p.\n", *device
);
122 static HRESULT WINAPI
d3d9_volume_SetPrivateData(IDirect3DVolume9
*iface
, REFGUID guid
,
123 const void *data
, DWORD data_size
, DWORD flags
)
125 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
126 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
127 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
129 return d3d9_resource_set_private_data(&volume
->resource
, guid
, data
, data_size
, flags
);
132 static HRESULT WINAPI
d3d9_volume_GetPrivateData(IDirect3DVolume9
*iface
, REFGUID guid
,
133 void *data
, DWORD
*data_size
)
135 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
136 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
137 iface
, debugstr_guid(guid
), data
, data_size
);
139 return d3d9_resource_get_private_data(&volume
->resource
, guid
, data
, data_size
);
142 static HRESULT WINAPI
d3d9_volume_FreePrivateData(IDirect3DVolume9
*iface
, REFGUID guid
)
144 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
145 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
147 return d3d9_resource_free_private_data(&volume
->resource
, guid
);
150 static HRESULT WINAPI
d3d9_volume_GetContainer(IDirect3DVolume9
*iface
, REFIID riid
, void **container
)
152 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
155 TRACE("iface %p, riid %s, container %p.\n", iface
, debugstr_guid(riid
), container
);
157 if (!volume
->container
)
158 return E_NOINTERFACE
;
160 hr
= IUnknown_QueryInterface(volume
->container
, riid
, container
);
162 TRACE("Returning %p,\n", *container
);
167 static HRESULT WINAPI
d3d9_volume_GetDesc(IDirect3DVolume9
*iface
, D3DVOLUME_DESC
*desc
)
169 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
170 struct wined3d_resource_desc wined3d_desc
;
171 struct wined3d_resource
*wined3d_resource
;
173 TRACE("iface %p, desc %p.\n", iface
, desc
);
175 wined3d_mutex_lock();
176 wined3d_resource
= wined3d_volume_get_resource(volume
->wined3d_volume
);
177 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
178 wined3d_mutex_unlock();
180 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
181 desc
->Type
= wined3d_desc
.resource_type
;
182 desc
->Usage
= wined3d_desc
.usage
& WINED3DUSAGE_MASK
;
183 desc
->Pool
= wined3d_desc
.pool
;
184 desc
->Width
= wined3d_desc
.width
;
185 desc
->Height
= wined3d_desc
.height
;
186 desc
->Depth
= wined3d_desc
.depth
;
191 static HRESULT WINAPI
d3d9_volume_LockBox(IDirect3DVolume9
*iface
,
192 D3DLOCKED_BOX
*locked_box
, const D3DBOX
*box
, DWORD flags
)
194 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
195 struct wined3d_map_desc map_desc
;
198 TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
199 iface
, locked_box
, box
, flags
);
201 wined3d_mutex_lock();
202 hr
= wined3d_volume_map(volume
->wined3d_volume
, &map_desc
, (const struct wined3d_box
*)box
, flags
);
203 wined3d_mutex_unlock();
205 locked_box
->RowPitch
= map_desc
.row_pitch
;
206 locked_box
->SlicePitch
= map_desc
.slice_pitch
;
207 locked_box
->pBits
= map_desc
.data
;
212 static HRESULT WINAPI
d3d9_volume_UnlockBox(IDirect3DVolume9
*iface
)
214 struct d3d9_volume
*volume
= impl_from_IDirect3DVolume9(iface
);
217 TRACE("iface %p.\n", iface
);
219 wined3d_mutex_lock();
220 hr
= wined3d_volume_unmap(volume
->wined3d_volume
);
221 wined3d_mutex_unlock();
226 static const struct IDirect3DVolume9Vtbl d3d9_volume_vtbl
=
229 d3d9_volume_QueryInterface
,
232 /* IDirect3DVolume9 */
233 d3d9_volume_GetDevice
,
234 d3d9_volume_SetPrivateData
,
235 d3d9_volume_GetPrivateData
,
236 d3d9_volume_FreePrivateData
,
237 d3d9_volume_GetContainer
,
240 d3d9_volume_UnlockBox
,
243 static void STDMETHODCALLTYPE
volume_wined3d_object_destroyed(void *parent
)
245 struct d3d9_volume
*volume
= parent
;
246 d3d9_resource_cleanup(&volume
->resource
);
247 HeapFree(GetProcessHeap(), 0, volume
);
250 static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops
=
252 volume_wined3d_object_destroyed
,
255 void volume_init(struct d3d9_volume
*volume
, struct wined3d_volume
*wined3d_volume
,
256 const struct wined3d_parent_ops
**parent_ops
)
258 volume
->IDirect3DVolume9_iface
.lpVtbl
= &d3d9_volume_vtbl
;
259 d3d9_resource_init(&volume
->resource
);
260 wined3d_volume_incref(wined3d_volume
);
261 volume
->wined3d_volume
= wined3d_volume
;
263 *parent_ops
= &d3d9_volume_wined3d_parent_ops
;