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
impl_from_IDirect3DVolume9(IDirect3DVolume9 * iface)27 static inline struct d3d9_volume *impl_from_IDirect3DVolume9(IDirect3DVolume9 *iface)
28 {
29 return CONTAINING_RECORD(iface, struct d3d9_volume, IDirect3DVolume9_iface);
30 }
31
d3d9_volume_QueryInterface(IDirect3DVolume9 * iface,REFIID riid,void ** out)32 static HRESULT WINAPI d3d9_volume_QueryInterface(IDirect3DVolume9 *iface, REFIID riid, void **out)
33 {
34 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
35
36 if (IsEqualGUID(riid, &IID_IDirect3DVolume9)
37 || IsEqualGUID(riid, &IID_IUnknown))
38 {
39 IDirect3DVolume9_AddRef(iface);
40 *out = iface;
41 return S_OK;
42 }
43
44 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
45
46 *out = NULL;
47 return E_NOINTERFACE;
48 }
49
d3d9_volume_AddRef(IDirect3DVolume9 * iface)50 static ULONG WINAPI d3d9_volume_AddRef(IDirect3DVolume9 *iface)
51 {
52 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
53
54 TRACE("iface %p.\n", iface);
55 TRACE("Forwarding to %p.\n", volume->texture);
56
57 return IDirect3DBaseTexture9_AddRef(&volume->texture->IDirect3DBaseTexture9_iface);
58 }
59
d3d9_volume_Release(IDirect3DVolume9 * iface)60 static ULONG WINAPI d3d9_volume_Release(IDirect3DVolume9 *iface)
61 {
62 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
63
64 TRACE("iface %p.\n", iface);
65 TRACE("Forwarding to %p.\n", volume->texture);
66
67 return IDirect3DBaseTexture9_Release(&volume->texture->IDirect3DBaseTexture9_iface);
68 }
69
d3d9_volume_GetDevice(IDirect3DVolume9 * iface,IDirect3DDevice9 ** device)70 static HRESULT WINAPI d3d9_volume_GetDevice(IDirect3DVolume9 *iface, IDirect3DDevice9 **device)
71 {
72 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
73
74 TRACE("iface %p, device %p.\n", iface, device);
75
76 return IDirect3DBaseTexture9_GetDevice(&volume->texture->IDirect3DBaseTexture9_iface, device);
77 }
78
d3d9_volume_SetPrivateData(IDirect3DVolume9 * iface,REFGUID guid,const void * data,DWORD data_size,DWORD flags)79 static HRESULT WINAPI d3d9_volume_SetPrivateData(IDirect3DVolume9 *iface, REFGUID guid,
80 const void *data, DWORD data_size, DWORD flags)
81 {
82 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
83 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
84 iface, debugstr_guid(guid), data, data_size, flags);
85
86 return d3d9_resource_set_private_data(&volume->resource, guid, data, data_size, flags);
87 }
88
d3d9_volume_GetPrivateData(IDirect3DVolume9 * iface,REFGUID guid,void * data,DWORD * data_size)89 static HRESULT WINAPI d3d9_volume_GetPrivateData(IDirect3DVolume9 *iface, REFGUID guid,
90 void *data, DWORD *data_size)
91 {
92 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
93 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
94 iface, debugstr_guid(guid), data, data_size);
95
96 return d3d9_resource_get_private_data(&volume->resource, guid, data, data_size);
97 }
98
d3d9_volume_FreePrivateData(IDirect3DVolume9 * iface,REFGUID guid)99 static HRESULT WINAPI d3d9_volume_FreePrivateData(IDirect3DVolume9 *iface, REFGUID guid)
100 {
101 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
102 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
103
104 return d3d9_resource_free_private_data(&volume->resource, guid);
105 }
106
d3d9_volume_GetContainer(IDirect3DVolume9 * iface,REFIID riid,void ** container)107 static HRESULT WINAPI d3d9_volume_GetContainer(IDirect3DVolume9 *iface, REFIID riid, void **container)
108 {
109 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
110
111 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), container);
112
113 return IDirect3DBaseTexture9_QueryInterface(&volume->texture->IDirect3DBaseTexture9_iface, riid, container);
114 }
115
d3d9_volume_GetDesc(IDirect3DVolume9 * iface,D3DVOLUME_DESC * desc)116 static HRESULT WINAPI d3d9_volume_GetDesc(IDirect3DVolume9 *iface, D3DVOLUME_DESC *desc)
117 {
118 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
119 struct wined3d_sub_resource_desc wined3d_desc;
120
121 TRACE("iface %p, desc %p.\n", iface, desc);
122
123 wined3d_mutex_lock();
124 wined3d_texture_get_sub_resource_desc(volume->wined3d_texture, volume->sub_resource_idx, &wined3d_desc);
125 wined3d_mutex_unlock();
126
127 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
128 desc->Type = D3DRTYPE_VOLUME;
129 desc->Usage = d3dusage_from_wined3dusage(wined3d_desc.usage);
130 desc->Pool = d3dpool_from_wined3daccess(wined3d_desc.access, wined3d_desc.usage);
131 desc->Width = wined3d_desc.width;
132 desc->Height = wined3d_desc.height;
133 desc->Depth = wined3d_desc.depth;
134
135 return D3D_OK;
136 }
137
d3d9_volume_LockBox(IDirect3DVolume9 * iface,D3DLOCKED_BOX * locked_box,const D3DBOX * box,DWORD flags)138 static HRESULT WINAPI d3d9_volume_LockBox(IDirect3DVolume9 *iface,
139 D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
140 {
141 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
142 struct wined3d_map_desc map_desc;
143 HRESULT hr;
144
145 TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
146 iface, locked_box, box, flags);
147
148 wined3d_mutex_lock();
149 if (FAILED(hr = wined3d_resource_map(wined3d_texture_get_resource(volume->wined3d_texture),
150 volume->sub_resource_idx, &map_desc, (const struct wined3d_box *)box,
151 wined3dmapflags_from_d3dmapflags(flags))))
152 map_desc.data = NULL;
153 wined3d_mutex_unlock();
154
155 locked_box->RowPitch = map_desc.row_pitch;
156 locked_box->SlicePitch = map_desc.slice_pitch;
157 locked_box->pBits = map_desc.data;
158
159 if (hr == E_INVALIDARG)
160 return D3DERR_INVALIDCALL;
161 return hr;
162 }
163
d3d9_volume_UnlockBox(IDirect3DVolume9 * iface)164 static HRESULT WINAPI d3d9_volume_UnlockBox(IDirect3DVolume9 *iface)
165 {
166 struct d3d9_volume *volume = impl_from_IDirect3DVolume9(iface);
167 HRESULT hr;
168
169 TRACE("iface %p.\n", iface);
170
171 wined3d_mutex_lock();
172 hr = wined3d_resource_unmap(wined3d_texture_get_resource(volume->wined3d_texture), volume->sub_resource_idx);
173 wined3d_mutex_unlock();
174
175 if (hr == WINEDDERR_NOTLOCKED)
176 return D3DERR_INVALIDCALL;
177 return hr;
178 }
179
180 static const struct IDirect3DVolume9Vtbl d3d9_volume_vtbl =
181 {
182 /* IUnknown */
183 d3d9_volume_QueryInterface,
184 d3d9_volume_AddRef,
185 d3d9_volume_Release,
186 /* IDirect3DVolume9 */
187 d3d9_volume_GetDevice,
188 d3d9_volume_SetPrivateData,
189 d3d9_volume_GetPrivateData,
190 d3d9_volume_FreePrivateData,
191 d3d9_volume_GetContainer,
192 d3d9_volume_GetDesc,
193 d3d9_volume_LockBox,
194 d3d9_volume_UnlockBox,
195 };
196
volume_wined3d_object_destroyed(void * parent)197 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
198 {
199 struct d3d9_volume *volume = parent;
200 d3d9_resource_cleanup(&volume->resource);
201 heap_free(volume);
202 }
203
204 static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
205 {
206 volume_wined3d_object_destroyed,
207 };
208
volume_init(struct d3d9_volume * volume,struct wined3d_texture * wined3d_texture,unsigned int sub_resource_idx,const struct wined3d_parent_ops ** parent_ops)209 void volume_init(struct d3d9_volume *volume, struct wined3d_texture *wined3d_texture,
210 unsigned int sub_resource_idx, const struct wined3d_parent_ops **parent_ops)
211 {
212 volume->IDirect3DVolume9_iface.lpVtbl = &d3d9_volume_vtbl;
213 d3d9_resource_init(&volume->resource);
214 volume->resource.refcount = 0;
215 volume->texture = wined3d_texture_get_parent(wined3d_texture);
216 volume->wined3d_texture = wined3d_texture;
217 volume->sub_resource_idx = sub_resource_idx;
218
219 *parent_ops = &d3d9_volume_wined3d_parent_ops;
220 }
221