volume.c 8.98 KB
Newer Older
1 2 3
/*
 * IDirect3DVolume9 implementation
 *
4
 * Copyright 2002-2005 Jason Edmeades
5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *                     Raphael Junqueira
 *
 * 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
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23 24
 */

#include "config.h"
#include "d3d9_private.h"

25
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26

27 28 29 30 31 32 33 34 35
static inline IDirect3DVolume9Impl *impl_from_IDirect3DVolume9(IDirect3DVolume9 *iface)
{
    return CONTAINING_RECORD(iface, IDirect3DVolume9Impl, IDirect3DVolume9_iface);
}

static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(IDirect3DVolume9 *iface, REFIID riid,
        void **ppobj)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
36

Henri Verbeet's avatar
Henri Verbeet committed
37 38
    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);

39 40
    if (IsEqualGUID(riid, &IID_IUnknown)
        || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
41
        IDirect3DVolume9_AddRef(iface);
42
        *ppobj = This;
H. Verbeet's avatar
H. Verbeet committed
43
        return S_OK;
44 45 46
    }

    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
H. Verbeet's avatar
H. Verbeet committed
47
    *ppobj = NULL;
48 49 50
    return E_NOINTERFACE;
}

51 52 53
static ULONG WINAPI IDirect3DVolume9Impl_AddRef(IDirect3DVolume9 *iface)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
54

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

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

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

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

74 75
        return ref;
    }
76 77
}

78 79 80
static ULONG WINAPI IDirect3DVolume9Impl_Release(IDirect3DVolume9 *iface)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
81

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

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

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

94
        if (ref == 0) {
95
            wined3d_mutex_lock();
96
            wined3d_volume_decref(This->wined3d_volume);
97
            wined3d_mutex_unlock();
98
        }
99

100
        return ref;
101 102 103
    }
}

104 105
static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(IDirect3DVolume9 *iface,
        IDirect3DDevice9 **device)
106
{
107
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
108 109
    IDirect3DResource9 *resource;
    HRESULT hr;
Henri Verbeet's avatar
Henri Verbeet committed
110

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

113 114 115 116 117
    hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
    if (SUCCEEDED(hr))
    {
        hr = IDirect3DResource9_GetDevice(resource, device);
        IDirect3DResource9_Release(resource);
Henri Verbeet's avatar
Henri Verbeet committed
118

119 120
        TRACE("Returning device %p.\n", *device);
    }
Henri Verbeet's avatar
Henri Verbeet committed
121

122
    return hr;
123 124
}

125 126 127 128
static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(IDirect3DVolume9 *iface, REFGUID refguid,
        const void *pData, DWORD SizeOfData, DWORD Flags)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
129
    struct wined3d_resource *resource;
Henri Verbeet's avatar
Henri Verbeet committed
130 131
    HRESULT hr;

Henri Verbeet's avatar
Henri Verbeet committed
132 133
    TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
Henri Verbeet's avatar
Henri Verbeet committed
134

135
    wined3d_mutex_lock();
136 137
    resource = wined3d_volume_get_resource(This->wined3d_volume);
    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
138
    wined3d_mutex_unlock();
Henri Verbeet's avatar
Henri Verbeet committed
139 140

    return hr;
141 142
}

143 144 145 146
static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(IDirect3DVolume9 *iface, REFGUID  refguid,
        void *pData, DWORD *pSizeOfData)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
147
    struct wined3d_resource *resource;
Henri Verbeet's avatar
Henri Verbeet committed
148 149
    HRESULT hr;

Henri Verbeet's avatar
Henri Verbeet committed
150 151
    TRACE("iface %p, guid %s, data %p, data_size %p.\n",
            iface, debugstr_guid(refguid), pData, pSizeOfData);
Henri Verbeet's avatar
Henri Verbeet committed
152

153
    wined3d_mutex_lock();
154 155
    resource = wined3d_volume_get_resource(This->wined3d_volume);
    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
156
    wined3d_mutex_unlock();
Henri Verbeet's avatar
Henri Verbeet committed
157 158

    return hr;
159 160
}

161 162 163
static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(IDirect3DVolume9 *iface, REFGUID refguid)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
164
    struct wined3d_resource *resource;
Henri Verbeet's avatar
Henri Verbeet committed
165 166
    HRESULT hr;

Henri Verbeet's avatar
Henri Verbeet committed
167
    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
Henri Verbeet's avatar
Henri Verbeet committed
168

169
    wined3d_mutex_lock();
170 171
    resource = wined3d_volume_get_resource(This->wined3d_volume);
    hr = wined3d_resource_free_private_data(resource, refguid);
172
    wined3d_mutex_unlock();
Henri Verbeet's avatar
Henri Verbeet committed
173 174

    return hr;
175 176
}

177 178 179 180
static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(IDirect3DVolume9 *iface, REFIID riid,
        void **ppContainer)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
181
    HRESULT res;
182

Henri Verbeet's avatar
Henri Verbeet committed
183
    TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
184

185 186 187
    if (!This->container) return E_NOINTERFACE;

    res = IUnknown_QueryInterface(This->container, riid, ppContainer);
188 189 190

    TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);

191
    return res;
192 193
}

194 195
static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(IDirect3DVolume9 *iface, D3DVOLUME_DESC *desc)
{
196
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
197
    struct wined3d_resource_desc wined3d_desc;
198
    struct wined3d_resource *wined3d_resource;
199

200
    TRACE("iface %p, desc %p.\n", iface, desc);
201

202
    wined3d_mutex_lock();
203
    wined3d_resource = wined3d_volume_get_resource(This->wined3d_volume);
204
    wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
205
    wined3d_mutex_unlock();
Henri Verbeet's avatar
Henri Verbeet committed
206

207 208 209 210 211 212 213
    desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
    desc->Type = wined3d_desc.resource_type;
    desc->Usage = wined3d_desc.usage;
    desc->Pool = wined3d_desc.pool;
    desc->Width = wined3d_desc.width;
    desc->Height = wined3d_desc.height;
    desc->Depth = wined3d_desc.depth;
214

215
    return D3D_OK;
216 217
}

218 219 220 221
static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(IDirect3DVolume9 *iface,
        D3DLOCKED_BOX *pLockedVolume, const D3DBOX *pBox, DWORD Flags)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
Henri Verbeet's avatar
Henri Verbeet committed
222 223
    HRESULT hr;

Henri Verbeet's avatar
Henri Verbeet committed
224 225
    TRACE("iface %p, locked_box %p, box %p, flags %#x.\n",
            iface, pLockedVolume, pBox, Flags);
Henri Verbeet's avatar
Henri Verbeet committed
226

227
    wined3d_mutex_lock();
228
    hr = wined3d_volume_map(This->wined3d_volume, (WINED3DLOCKED_BOX *)pLockedVolume,
Henri Verbeet's avatar
Henri Verbeet committed
229
            (const WINED3DBOX *)pBox, Flags);
230
    wined3d_mutex_unlock();
Henri Verbeet's avatar
Henri Verbeet committed
231 232

    return hr;
233 234
}

235 236 237
static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(IDirect3DVolume9 *iface)
{
    IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
Henri Verbeet's avatar
Henri Verbeet committed
238 239
    HRESULT hr;

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

242
    wined3d_mutex_lock();
243
    hr = wined3d_volume_unmap(This->wined3d_volume);
244
    wined3d_mutex_unlock();
Henri Verbeet's avatar
Henri Verbeet committed
245 246

    return hr;
247 248
}

249
static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
250
{
251
    /* IUnknown */
252 253 254
    IDirect3DVolume9Impl_QueryInterface,
    IDirect3DVolume9Impl_AddRef,
    IDirect3DVolume9Impl_Release,
255
    /* IDirect3DVolume9 */
256 257 258 259 260 261 262 263 264
    IDirect3DVolume9Impl_GetDevice,
    IDirect3DVolume9Impl_SetPrivateData,
    IDirect3DVolume9Impl_GetPrivateData,
    IDirect3DVolume9Impl_FreePrivateData,
    IDirect3DVolume9Impl_GetContainer,
    IDirect3DVolume9Impl_GetDesc,
    IDirect3DVolume9Impl_LockBox,
    IDirect3DVolume9Impl_UnlockBox
};
265

266 267 268
static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
{
    HeapFree(GetProcessHeap(), 0, parent);
269
}
270

271 272 273 274 275
static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
{
    volume_wined3d_object_destroyed,
};

276
HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
277
        UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool)
278 279 280
{
    HRESULT hr;

281
    volume->IDirect3DVolume9_iface.lpVtbl = &Direct3DVolume9_Vtbl;
282 283
    volume->ref = 1;

284
    hr = wined3d_volume_create(device->wined3d_device, width, height, depth, usage & WINED3DUSAGE_MASK,
285
            format, pool, volume, &d3d9_volume_wined3d_parent_ops, &volume->wined3d_volume);
286 287 288 289 290 291 292 293
    if (FAILED(hr))
    {
        WARN("Failed to create wined3d volume, hr %#x.\n", hr);
        return hr;
    }

    return D3D_OK;
}