volume.c 8.83 KB
Newer Older
1 2 3
/*
 * IDirect3DVolume8 implementation
 *
4
 * Copyright 2005 Oliver Stieber
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 "config.h"
22 23
#include "d3d8_private.h"

24
WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25

26
static inline struct d3d8_volume *impl_from_IDirect3DVolume8(IDirect3DVolume8 *iface)
27
{
28
    return CONTAINING_RECORD(iface, struct d3d8_volume, IDirect3DVolume8_iface);
29 30
}

31
static HRESULT WINAPI d3d8_volume_QueryInterface(IDirect3DVolume8 *iface, REFIID riid, void **out)
32
{
33
    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), out);
Henri Verbeet's avatar
Henri Verbeet committed
34

35 36 37
    if (IsEqualGUID(riid, &IID_IDirect3DVolume8)
            || IsEqualGUID(riid, &IID_IUnknown))
    {
38
        IDirect3DVolume8_AddRef(iface);
39
        *out = iface;
H. Verbeet's avatar
H. Verbeet committed
40
        return S_OK;
41 42
    }

43 44
    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));

45
    *out = NULL;
46 47 48
    return E_NOINTERFACE;
}

49
static ULONG WINAPI d3d8_volume_AddRef(IDirect3DVolume8 *iface)
50
{
51
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
52

Henri Verbeet's avatar
Henri Verbeet committed
53
    TRACE("iface %p.\n", iface);
54

55 56
    if (volume->forwardReference)
    {
57
        /* Forward to the containerParent */
58 59 60 61 62
        TRACE("Forwarding to %p,\n", volume->forwardReference);
        return IUnknown_AddRef(volume->forwardReference);
    }
    else
    {
63
        /* No container, handle our own refcounting */
64
        ULONG ref = InterlockedIncrement(&volume->refcount);
Henri Verbeet's avatar
Henri Verbeet committed
65 66

        TRACE("%p increasing refcount to %u.\n", iface, ref);
67 68 69 70

        if (ref == 1)
        {
            wined3d_mutex_lock();
71
            wined3d_volume_incref(volume->wined3d_volume);
72 73 74
            wined3d_mutex_unlock();
        }

75 76
        return ref;
    }
77 78
}

79
static ULONG WINAPI d3d8_volume_Release(IDirect3DVolume8 *iface)
80
{
81
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
82

Henri Verbeet's avatar
Henri Verbeet committed
83
    TRACE("iface %p.\n", iface);
84

85 86
    if (volume->forwardReference)
    {
87
        /* Forward to the containerParent */
88 89
        TRACE("Forwarding to %p.\n", volume->forwardReference);
        return IUnknown_Release(volume->forwardReference);
90
    }
91 92
    else
    {
93
        /* No container, handle our own refcounting */
94
        ULONG ref = InterlockedDecrement(&volume->refcount);
Henri Verbeet's avatar
Henri Verbeet committed
95 96

        TRACE("%p decreasing refcount to %u.\n", iface, ref);
97

98 99
        if (!ref)
        {
100
            wined3d_mutex_lock();
101
            wined3d_volume_decref(volume->wined3d_volume);
102
            wined3d_mutex_unlock();
103
        }
104

105
        return ref;
106
    }
107 108
}

109
static HRESULT WINAPI d3d8_volume_GetDevice(IDirect3DVolume8 *iface, IDirect3DDevice8 **device)
110
{
111
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
112 113
    IDirect3DResource8 *resource;
    HRESULT hr;
114

115
    TRACE("iface %p, device %p.\n", iface, device);
Henri Verbeet's avatar
Henri Verbeet committed
116

117
    hr = IUnknown_QueryInterface(volume->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
118 119 120 121
    if (SUCCEEDED(hr))
    {
        hr = IDirect3DResource8_GetDevice(resource, device);
        IDirect3DResource8_Release(resource);
122

123 124 125 126
        TRACE("Returning device %p.\n", *device);
    }

    return hr;
127
}
128

129 130
static HRESULT WINAPI d3d8_volume_SetPrivateData(IDirect3DVolume8 *iface, REFGUID guid,
        const void *data, DWORD data_size, DWORD flags)
131
{
132
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
133
    struct wined3d_resource *resource;
134
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
135 136

    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
137
            iface, debugstr_guid(guid), data, data_size, flags);
138

139
    wined3d_mutex_lock();
140 141
    resource = wined3d_volume_get_resource(volume->wined3d_volume);
    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
142 143
    wined3d_mutex_unlock();

144
    return hr;
145
}
146

147 148
static HRESULT WINAPI d3d8_volume_GetPrivateData(IDirect3DVolume8 *iface, REFGUID  guid,
        void *data, DWORD *data_size)
149
{
150
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
151
    struct wined3d_resource *resource;
152
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
153 154

    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
155
            iface, debugstr_guid(guid), data, data_size);
156

157
    wined3d_mutex_lock();
158 159
    resource = wined3d_volume_get_resource(volume->wined3d_volume);
    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
160 161
    wined3d_mutex_unlock();

162
    return hr;
163
}
164

165
static HRESULT WINAPI d3d8_volume_FreePrivateData(IDirect3DVolume8 *iface, REFGUID guid)
166
{
167
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
168
    struct wined3d_resource *resource;
169
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
170

171
    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
172

173
    wined3d_mutex_lock();
174 175
    resource = wined3d_volume_get_resource(volume->wined3d_volume);
    hr = wined3d_resource_free_private_data(resource, guid);
176 177
    wined3d_mutex_unlock();

178
    return hr;
179
}
180

181
static HRESULT WINAPI d3d8_volume_GetContainer(IDirect3DVolume8 *iface, REFIID riid, void **container)
182
{
183
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
184 185
    HRESULT res;

Henri Verbeet's avatar
Henri Verbeet committed
186
    TRACE("iface %p, riid %s, container %p.\n",
187
            iface, debugstr_guid(riid), container);
188

189 190
    if (!volume->container)
        return E_NOINTERFACE;
191

192
    res = IUnknown_QueryInterface(volume->container, riid, container);
193

194
    TRACE("Returning %p.\n", *container);
195

196
    return res;
197
}
198

199
static HRESULT WINAPI d3d8_volume_GetDesc(IDirect3DVolume8 *iface, D3DVOLUME_DESC *desc)
200
{
201
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
202
    struct wined3d_resource_desc wined3d_desc;
203
    struct wined3d_resource *wined3d_resource;
204

205
    TRACE("iface %p, desc %p.\n", iface, desc);
206

207
    wined3d_mutex_lock();
208
    wined3d_resource = wined3d_volume_get_resource(volume->wined3d_volume);
209
    wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
210
    wined3d_mutex_unlock();
211

212 213
    desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
    desc->Type = wined3d_desc.resource_type;
214
    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
215 216 217 218 219
    desc->Pool = wined3d_desc.pool;
    desc->Size = wined3d_desc.size;
    desc->Width = wined3d_desc.width;
    desc->Height = wined3d_desc.height;
    desc->Depth = wined3d_desc.depth;
220

221
    return D3D_OK;
222
}
223

224
static HRESULT WINAPI d3d8_volume_LockBox(IDirect3DVolume8 *iface,
225
        D3DLOCKED_BOX *locked_box, const D3DBOX *box, DWORD flags)
226
{
227
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
228
    struct wined3d_map_desc map_desc;
229
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
230 231

    TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
232
            iface, locked_box, box, flags);
233

234
    wined3d_mutex_lock();
235
    hr = wined3d_volume_map(volume->wined3d_volume, &map_desc, (const struct wined3d_box *)box, flags);
236 237
    wined3d_mutex_unlock();

238 239 240 241
    locked_box->RowPitch = map_desc.row_pitch;
    locked_box->SlicePitch = map_desc.slice_pitch;
    locked_box->pBits = map_desc.data;

242
    return hr;
243
}
244

245
static HRESULT WINAPI d3d8_volume_UnlockBox(IDirect3DVolume8 *iface)
246
{
247
    struct d3d8_volume *volume = impl_from_IDirect3DVolume8(iface);
248
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
249 250

    TRACE("iface %p.\n", iface);
251

252
    wined3d_mutex_lock();
253
    hr = wined3d_volume_unmap(volume->wined3d_volume);
254 255
    wined3d_mutex_unlock();

256
    return hr;
257 258
}

259
static const IDirect3DVolume8Vtbl d3d8_volume_vtbl =
260
{
261
    /* IUnknown */
262 263 264
    d3d8_volume_QueryInterface,
    d3d8_volume_AddRef,
    d3d8_volume_Release,
265
    /* IDirect3DVolume8 */
266 267 268 269 270 271 272 273
    d3d8_volume_GetDevice,
    d3d8_volume_SetPrivateData,
    d3d8_volume_GetPrivateData,
    d3d8_volume_FreePrivateData,
    d3d8_volume_GetContainer,
    d3d8_volume_GetDesc,
    d3d8_volume_LockBox,
    d3d8_volume_UnlockBox,
274
};
275

276 277 278
static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
{
    HeapFree(GetProcessHeap(), 0, parent);
279
}
280

281 282 283 284 285
static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
{
    volume_wined3d_object_destroyed,
};

286
HRESULT volume_init(struct d3d8_volume *volume, struct d3d8_device *device, UINT width, UINT height,
287
        UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool)
288 289 290
{
    HRESULT hr;

291 292
    volume->IDirect3DVolume8_iface.lpVtbl = &d3d8_volume_vtbl;
    volume->refcount = 1;
293

294
    hr = wined3d_volume_create(device->wined3d_device, width, height, depth, usage,
295
            format, pool, volume, &d3d8_volume_wined3d_parent_ops, &volume->wined3d_volume);
296 297 298 299 300 301 302 303
    if (FAILED(hr))
    {
        WARN("Failed to create wined3d volume, hr %#x.\n", hr);
        return hr;
    }

    return D3D_OK;
}