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