d3d9: Return D3DERR_INVALIDCALL when IDirect3DCubeTexture9::GetLevelDesc is called...
[wine/multimedia.git] / dlls / quartz / enumfilters.c
blob2b9dc53c75d67fb26770fa2b60618d7dd0adfde3
1 /*
2 * Implementation of IEnumFilters Interface
4 * Copyright 2004 Christian Costa
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.
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.
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
21 #include "quartz_private.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(quartz);
27 typedef struct IEnumFiltersImpl
29 IEnumFilters IEnumFilters_iface;
30 LONG refCount;
31 IBaseFilter ** ppFilters;
32 int nFilters;
33 ULONG uIndex;
34 } IEnumFiltersImpl;
36 static const struct IEnumFiltersVtbl IEnumFiltersImpl_Vtbl;
38 static inline IEnumFiltersImpl *impl_from_IEnumFilters(IEnumFilters *iface)
40 return CONTAINING_RECORD(iface, IEnumFiltersImpl, IEnumFilters_iface);
43 HRESULT IEnumFiltersImpl_Construct(IBaseFilter ** ppFilters, ULONG nFilters, IEnumFilters ** ppEnum)
45 /* Note: The incoming IBaseFilter interfaces are not AddRef'd here as in Windows,
46 * they should have been previously AddRef'd. */
47 IEnumFiltersImpl * pEnumFilters = CoTaskMemAlloc(sizeof(IEnumFiltersImpl));
49 TRACE("(%p, %d, %p)\n", ppFilters, nFilters, ppEnum);
51 *ppEnum = NULL;
53 if (!pEnumFilters)
55 return E_OUTOFMEMORY;
58 pEnumFilters->IEnumFilters_iface.lpVtbl = &IEnumFiltersImpl_Vtbl;
59 pEnumFilters->refCount = 1;
60 pEnumFilters->uIndex = 0;
61 pEnumFilters->nFilters = nFilters;
62 pEnumFilters->ppFilters = CoTaskMemAlloc(sizeof(IBaseFilter*) * nFilters);
63 if (!pEnumFilters->ppFilters)
65 CoTaskMemFree(pEnumFilters);
66 return E_OUTOFMEMORY;
69 memcpy(pEnumFilters->ppFilters, ppFilters, nFilters * sizeof(IBaseFilter*));
71 *ppEnum = &pEnumFilters->IEnumFilters_iface;
72 return S_OK;
75 static HRESULT WINAPI IEnumFiltersImpl_QueryInterface(IEnumFilters * iface, REFIID riid, LPVOID * ppv)
77 TRACE("(%p)->(%s, %p)\n", iface, qzdebugstr_guid(riid), ppv);
79 *ppv = NULL;
81 if (IsEqualIID(riid, &IID_IUnknown))
82 *ppv = iface;
83 else if (IsEqualIID(riid, &IID_IEnumFilters))
84 *ppv = iface;
86 if (*ppv)
88 IUnknown_AddRef((IUnknown *)(*ppv));
89 return S_OK;
92 FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
94 return E_NOINTERFACE;
97 static ULONG WINAPI IEnumFiltersImpl_AddRef(IEnumFilters * iface)
99 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
100 ULONG refCount = InterlockedIncrement(&This->refCount);
102 TRACE("(%p)->()\n", iface);
104 return refCount;
107 static ULONG WINAPI IEnumFiltersImpl_Release(IEnumFilters * iface)
109 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
110 ULONG refCount = InterlockedDecrement(&This->refCount);
112 TRACE("(%p)->()\n", iface);
114 if (!refCount)
116 CoTaskMemFree(This->ppFilters);
117 CoTaskMemFree(This);
118 return 0;
120 else
121 return refCount;
124 static HRESULT WINAPI IEnumFiltersImpl_Next(IEnumFilters * iface, ULONG cFilters, IBaseFilter ** ppFilters, ULONG * pcFetched)
126 ULONG cFetched;
127 ULONG i;
128 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
130 cFetched = min(This->nFilters, This->uIndex + cFilters) - This->uIndex;
132 TRACE("(%p)->(%u, %p, %p)\n", iface, cFilters, ppFilters, pcFetched);
134 if (!ppFilters)
135 return E_POINTER;
137 for (i = 0; i < cFetched; i++)
139 ppFilters[i] = This->ppFilters[This->uIndex + i];
140 IBaseFilter_AddRef(ppFilters[i]);
143 This->uIndex += cFetched;
145 if (pcFetched)
146 *pcFetched = cFetched;
148 if (cFetched != cFilters)
149 return S_FALSE;
150 return S_OK;
153 static HRESULT WINAPI IEnumFiltersImpl_Skip(IEnumFilters * iface, ULONG cFilters)
155 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
157 TRACE("(%p)->(%u)\n", iface, cFilters);
159 if (This->uIndex + cFilters < This->nFilters)
161 This->uIndex += cFilters;
162 return S_OK;
164 return S_FALSE;
167 static HRESULT WINAPI IEnumFiltersImpl_Reset(IEnumFilters * iface)
169 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
171 TRACE("(%p)->()\n", iface);
173 This->uIndex = 0;
174 return S_OK;
177 static HRESULT WINAPI IEnumFiltersImpl_Clone(IEnumFilters * iface, IEnumFilters ** ppEnum)
179 HRESULT hr;
180 IEnumFiltersImpl *This = impl_from_IEnumFilters(iface);
182 TRACE("(%p)->(%p)\n", iface, ppEnum);
184 hr = IEnumFiltersImpl_Construct(This->ppFilters, This->nFilters, ppEnum);
185 if (FAILED(hr))
186 return hr;
187 return IEnumFilters_Skip(*ppEnum, This->uIndex);
190 static const IEnumFiltersVtbl IEnumFiltersImpl_Vtbl =
192 IEnumFiltersImpl_QueryInterface,
193 IEnumFiltersImpl_AddRef,
194 IEnumFiltersImpl_Release,
195 IEnumFiltersImpl_Next,
196 IEnumFiltersImpl_Skip,
197 IEnumFiltersImpl_Reset,
198 IEnumFiltersImpl_Clone