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

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

26
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 28

/* IDirect3DQuery9 IUnknown parts follow: */
29
static HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(LPDIRECT3DQUERY9 iface, REFIID riid, LPVOID* ppobj) {
30
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
31
    TRACE("(%p) Relay\n", This);
32 33 34

    if (IsEqualGUID(riid, &IID_IUnknown)
        || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
35
        IUnknown_AddRef(iface);
36
        *ppobj = This;
H. Verbeet's avatar
H. Verbeet committed
37
        return S_OK;
38 39 40
    }

    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
H. Verbeet's avatar
H. Verbeet committed
41
    *ppobj = NULL;
42 43 44
    return E_NOINTERFACE;
}

45
static ULONG WINAPI IDirect3DQuery9Impl_AddRef(LPDIRECT3DQUERY9 iface) {
46
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
47 48 49 50
    ULONG ref = InterlockedIncrement(&This->ref);

    TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
    return ref;
51 52
}

53
static ULONG WINAPI IDirect3DQuery9Impl_Release(LPDIRECT3DQUERY9 iface) {
54
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
55 56 57 58
    ULONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) : ReleaseRef to %ld\n", This, ref);

59
    if (ref == 0) {
60
        IUnknown_Release(This->parentDevice);
61 62 63 64 65 66
        HeapFree(GetProcessHeap(), 0, This);
    }
    return ref;
}

/* IDirect3DQuery9 Interface follow: */
67
static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(LPDIRECT3DQUERY9 iface, IDirect3DDevice9** ppDevice) {
68
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
69 70 71 72 73 74 75 76 77 78 79 80 81
    IWineD3DDevice* pDevice;
    HRESULT hr;

    TRACE("(%p) Relay\n", This);

    hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
    if(hr != D3D_OK){
        *ppDevice = NULL;
    }else{
        hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
        IWineD3DDevice_Release(pDevice);
    }
    return hr;
82 83
}

84
static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
85
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
86 87
    TRACE("(%p) Relay\n", This);
    return IWineD3DQuery_GetType(This->wineD3DQuery);
88 89
}

90
static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
91
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
92 93
    TRACE("(%p) Relay\n", This);
    return IWineD3DQuery_GetDataSize(This->wineD3DQuery);
94 95
}

96
static HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
97
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
98 99
    TRACE("(%p) Relay\n", This);
    return IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
100 101
}

102
static HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
103
    IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
104 105
    TRACE("(%p) Relay\n", This);
    return IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
106 107 108
}


109
static const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
110 111 112 113 114 115 116 117 118 119 120 121 122 123
{
    IDirect3DQuery9Impl_QueryInterface,
    IDirect3DQuery9Impl_AddRef,
    IDirect3DQuery9Impl_Release,
    IDirect3DQuery9Impl_GetDevice,
    IDirect3DQuery9Impl_GetType,
    IDirect3DQuery9Impl_GetDataSize,
    IDirect3DQuery9Impl_Issue,
    IDirect3DQuery9Impl_GetData
};


/* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */
HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9 iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) {
124 125 126 127 128 129 130 131 132 133 134 135
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
    IDirect3DQuery9Impl *object = NULL;
    HRESULT hr = D3D_OK;

    TRACE("(%p) Relay\n", This);

    if (!ppQuery)
        return IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);

    /* Allocate the storage for the device */
    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
    if (NULL == object) {
136
        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
137 138 139 140 141 142 143 144
        return D3DERR_OUTOFVIDEOMEMORY;
    }

    object->lpVtbl = &Direct3DQuery9_Vtbl;
    object->ref = 1;
    hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);

    if (FAILED(hr)) {
145

146 147 148 149
        /* free up object */
        FIXME("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
        HeapFree(GetProcessHeap(), 0, object);
    } else {
150 151
        IUnknown_AddRef(iface);
        object->parentDevice = iface;
152
        *ppQuery = (LPDIRECT3DQUERY9) object;
153
        TRACE("(%p) : Created query %p\n", This , object);
154 155 156
    }
    TRACE("(%p) : returning %lx\n", This, hr);
    return hr;
157
}