8c94f53d3a7d50d94348cc1aee8a007e7f7967b6
[reactos.git] / reactos / dll / directx / wine / d3d8 / volume.c
1 /*
2 * IDirect3DVolume8 implementation
3 *
4 * Copyright 2005 Oliver Stieber
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "d3d8_private.h"
22
23 static inline struct d3d8_volume *impl_from_IDirect3DVolume8(IDirect3DVolume8 *iface)
24 {
25 return CONTAINING_RECORD(iface, struct d3d8_volume, IDirect3DVolume8_iface);
26 }
27
28 static HRESULT WINAPI d3d8_volume_QueryInterface(IDirect3DVolume8 *iface, REFIID riid, void **out)
29 {
30 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), out);
31
32 if (IsEqualGUID(riid, &IID_IDirect3DVolume8)
33 || IsEqualGUID(riid, &IID_IUnknown))
34 {
35 IDirect3DVolume8_AddRef(iface);
36 *out = iface;
37 return S_OK;
38 }
39
40 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
41
42 *out = NULL;
43 return E_NOINTERFACE;
44 }
45
46 static ULONG WINAPI d3d8_volume_AddRef(IDirect3DVolume8 *iface)
47 {
48 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
49
50 TRACE("iface %p.\n", iface);
51 TRACE("Forwarding to %p.\n", volume->texture);
52
53 return IDirect3DBaseTexture8_AddRef(&volume->texture->IDirect3DBaseTexture8_iface);
54 }
55
56 static ULONG WINAPI d3d8_volume_Release(IDirect3DVolume8 *iface)
57 {
58 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
59
60 TRACE("iface %p.\n", iface);
61 TRACE("Forwarding to %p.\n", volume->texture);
62
63 return IDirect3DBaseTexture8_Release(&volume->texture->IDirect3DBaseTexture8_iface);
64 }
65
66 static HRESULT WINAPI d3d8_volume_GetDevice(IDirect3DVolume8 *iface, IDirect3DDevice8 **device)
67 {
68 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
69
70 TRACE("iface %p, device %p.\n", iface, device);
71
72 return IDirect3DBaseTexture8_GetDevice(&volume->texture->IDirect3DBaseTexture8_iface, device);
73 }
74
75 static HRESULT WINAPI d3d8_volume_SetPrivateData(IDirect3DVolume8 *iface, REFGUID guid,
76 const void *data, DWORD data_size, DWORD flags)
77 {
78 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
79 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
80 iface, debugstr_guid(guid), data, data_size, flags);
81
82 return d3d8_resource_set_private_data(&volume->resource, guid, data, data_size, flags);
83 }
84
85 static HRESULT WINAPI d3d8_volume_GetPrivateData(IDirect3DVolume8 *iface, REFGUID guid,
86 void *data, DWORD *data_size)
87 {
88 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
89 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
90 iface, debugstr_guid(guid), data, data_size);
91
92 return d3d8_resource_get_private_data(&volume->resource, guid, data, data_size);
93 }
94
95 static HRESULT WINAPI d3d8_volume_FreePrivateData(IDirect3DVolume8 *iface, REFGUID guid)
96 {
97 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
98 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
99
100 return d3d8_resource_free_private_data(&volume->resource, guid);
101 }
102
103 static HRESULT WINAPI d3d8_volume_GetContainer(IDirect3DVolume8 *iface, REFIID riid, void **container)
104 {
105 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
106
107 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), container);
108
109 return IDirect3DBaseTexture8_QueryInterface(&volume->texture->IDirect3DBaseTexture8_iface, riid, container);
110 }
111
112 static HRESULT WINAPI d3d8_volume_GetDesc(IDirect3DVolume8 *iface, D3DVOLUME_DESC *desc)
113 {
114 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
115 struct wined3d_resource_desc wined3d_desc;
116 struct wined3d_resource *wined3d_resource;
117
118 TRACE("iface %p, desc %p.\n", iface, desc);
119
120 wined3d_mutex_lock();
121 wined3d_resource = wined3d_volume_get_resource(volume->wined3d_volume);
122 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
123 wined3d_mutex_unlock();
124
125 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
126 desc->Type = wined3d_desc.resource_type;
127 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
128 desc->Pool = wined3d_desc.pool;
129 desc->Size = wined3d_desc.size;
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 d3d8_volume_LockBox(IDirect3DVolume8 *iface,
138 D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
139 {
140 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(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_volume_map(volume->wined3d_volume, &map_desc, (const struct wined3d_box *)box, flags);
149 wined3d_mutex_unlock();
150
151 locked_box->RowPitch = map_desc.row_pitch;
152 locked_box->SlicePitch = map_desc.slice_pitch;
153 locked_box->pBits = map_desc.data;
154
155 return hr;
156 }
157
158 static HRESULT WINAPI d3d8_volume_UnlockBox(IDirect3DVolume8 *iface)
159 {
160 struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
161 HRESULT hr;
162
163 TRACE("iface %p.\n", iface);
164
165 wined3d_mutex_lock();
166 hr = wined3d_volume_unmap(volume->wined3d_volume);
167 wined3d_mutex_unlock();
168
169 return hr;
170 }
171
172 static const IDirect3DVolume8Vtbl d3d8_volume_vtbl =
173 {
174 /* IUnknown */
175 d3d8_volume_QueryInterface,
176 d3d8_volume_AddRef,
177 d3d8_volume_Release,
178 /* IDirect3DVolume8 */
179 d3d8_volume_GetDevice,
180 d3d8_volume_SetPrivateData,
181 d3d8_volume_GetPrivateData,
182 d3d8_volume_FreePrivateData,
183 d3d8_volume_GetContainer,
184 d3d8_volume_GetDesc,
185 d3d8_volume_LockBox,
186 d3d8_volume_UnlockBox,
187 };
188
189 static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
190 {
191 struct d3d8_volume *volume = parent;
192 d3d8_resource_cleanup(&volume->resource);
193 HeapFree(GetProcessHeap(), 0, volume);
194 }
195
196 static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
197 {
198 volume_wined3d_object_destroyed,
199 };
200
201 void volume_init(struct d3d8_volume *volume, struct d3d8_texture *texture,
202 struct wined3d_volume *wined3d_volume, const struct wined3d_parent_ops **parent_ops)
203 {
204 volume->IDirect3DVolume8_iface.lpVtbl = &d3d8_volume_vtbl;
205 d3d8_resource_init(&volume->resource);
206 volume->resource.refcount = 0;
207 volume->wined3d_volume = wined3d_volume;
208 volume->texture = texture;
209
210 *parent_ops = &d3d8_volume_wined3d_parent_ops;
211 }