mshtml: Added beginning OnDataAvailable implementation.
[wine] / dlls / d3d9 / query.c
1 /*
2  * IDirect3DQuery9 implementation
3  *
4  * Copyright 2002-2003 Raphael Junqueira
5  * Copyright 2002-2003 Jason Edmeades
6  * Copyright 2005 Oliver Stieber
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * 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 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28 /* IDirect3DQuery9 IUnknown parts follow: */
29 HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(LPDIRECT3DQUERY9 iface, REFIID riid, LPVOID* ppobj) {
30     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
31     TRACE("(%p) Relay\n", This);
32
33     if (IsEqualGUID(riid, &IID_IUnknown)
34         || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
35         IUnknown_AddRef(iface);
36         *ppobj = This;
37         return D3D_OK;
38     }
39
40     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41     return E_NOINTERFACE;
42 }
43
44 ULONG WINAPI IDirect3DQuery9Impl_AddRef(LPDIRECT3DQUERY9 iface) {
45     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
46     ULONG ref = InterlockedIncrement(&This->ref);
47
48     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
49     return ref;
50 }
51
52 ULONG WINAPI IDirect3DQuery9Impl_Release(LPDIRECT3DQUERY9 iface) {
53     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
57
58     if (ref == 0) {
59         IUnknown_Release(This->parentDevice);
60         HeapFree(GetProcessHeap(), 0, This);
61     }
62     return ref;
63 }
64
65 /* IDirect3DQuery9 Interface follow: */
66 HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(LPDIRECT3DQUERY9 iface, IDirect3DDevice9** ppDevice) {
67     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
68     IWineD3DDevice* pDevice;
69     HRESULT hr;
70
71     TRACE("(%p) Relay\n", This);
72
73     hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
74     if(hr != D3D_OK){
75         *ppDevice = NULL;
76     }else{
77         hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
78         IWineD3DDevice_Release(pDevice);
79     }
80     return hr;
81 }
82
83 D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
84     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
85     TRACE("(%p) Relay\n", This);
86     return IWineD3DQuery_GetType(This->wineD3DQuery);
87 }
88
89 DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
90     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
91     TRACE("(%p) Relay\n", This);
92     return IWineD3DQuery_GetDataSize(This->wineD3DQuery);
93 }
94
95 HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
96     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
97     TRACE("(%p) Relay\n", This);
98     return IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
99 }
100
101 HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
102     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
103     TRACE("(%p) Relay\n", This);
104     return IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
105 }
106
107
108 const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
109 {
110     IDirect3DQuery9Impl_QueryInterface,
111     IDirect3DQuery9Impl_AddRef,
112     IDirect3DQuery9Impl_Release,
113     IDirect3DQuery9Impl_GetDevice,
114     IDirect3DQuery9Impl_GetType,
115     IDirect3DQuery9Impl_GetDataSize,
116     IDirect3DQuery9Impl_Issue,
117     IDirect3DQuery9Impl_GetData
118 };
119
120
121 /* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */
122 HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9 iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) {
123     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
124     IDirect3DQuery9Impl *object = NULL;
125     HRESULT hr = D3D_OK;
126
127     TRACE("(%p) Relay\n", This);
128
129     if (!ppQuery)
130         return IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
131
132     /* Allocate the storage for the device */
133     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
134     if (NULL == object) {
135         FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
136         return D3DERR_OUTOFVIDEOMEMORY;
137     }
138
139     object->lpVtbl = &Direct3DQuery9_Vtbl;
140     object->ref = 1;
141     hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
142
143     if (FAILED(hr)) {
144
145         /* free up object */
146         FIXME("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
147         HeapFree(GetProcessHeap(), 0, object);
148     } else {
149         IUnknown_AddRef(iface);
150         object->parentDevice = iface;
151         *ppQuery = (LPDIRECT3DQUERY9) object;
152         TRACE("(%p) : Created query %p\n", This , object);
153     }
154     TRACE("(%p) : returning %lx\n", This, hr);
155     return hr;
156 }