2 * IWineD3DResource Implementation
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wined3d_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
28 #define GLINFO_LOCATION ((IWineD3DImpl *)(((IWineD3DDeviceImpl *)This->resource.wineD3DDevice)->wineD3D))->gl_info
30 /* IWineD3DResource IUnknown parts follow: */
31 HRESULT WINAPI IWineD3DResourceImpl_QueryInterface(IWineD3DResource *iface, REFIID riid, LPVOID *ppobj)
33 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
34 TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
35 if (IsEqualGUID(riid, &IID_IUnknown)
36 || IsEqualGUID(riid, &IID_IWineD3DBase)
37 || IsEqualGUID(riid, &IID_IWineD3DResource)) {
38 IUnknown_AddRef(iface);
46 ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface) {
47 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
48 ULONG ref = InterlockedIncrement(&This->resource.ref);
49 TRACE("(%p) : AddRef increasing from %d\n", This, ref - 1);
53 ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface) {
54 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
55 ULONG ref = InterlockedDecrement(&This->resource.ref);
56 TRACE("(%p) : Releasing from %d\n", This, ref + 1);
58 IWineD3DResourceImpl_CleanUp(iface);
59 HeapFree(GetProcessHeap(), 0, This);
64 /* class static (not in vtable) */
65 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface){
66 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
67 TRACE("(%p) Cleaning up resource\n", This);
68 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
69 TRACE("Decrementing device memory pool by %u\n", This->resource.size);
70 globalChangeGlRam(-This->resource.size);
73 HeapFree(GetProcessHeap(), 0, This->resource.allocatedMemory);
74 This->resource.allocatedMemory = 0;
76 if (This->resource.wineD3DDevice != NULL) {
77 IWineD3DDevice_ResourceReleased((IWineD3DDevice *)This->resource.wineD3DDevice, iface);
78 }/* NOTE: this is not really an error for systemmem resoruces */
82 /* IWineD3DResource Interface follow: */
83 HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice** ppDevice) {
84 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
85 TRACE("(%p) : returning %p\n", This, This->resource.wineD3DDevice);
86 *ppDevice = (IWineD3DDevice *) This->resource.wineD3DDevice;
87 IWineD3DDevice_AddRef(*ppDevice);
91 static PrivateData* IWineD3DResourceImpl_FindPrivateData(IWineD3DResourceImpl *This,
97 TRACE("Searching for private data %s\n", debugstr_guid(tag));
98 LIST_FOR_EACH(entry, &This->resource.privateData)
100 data = LIST_ENTRY(entry, PrivateData, entry);
101 if (IsEqualGUID(&data->tag, tag)) {
102 TRACE("Found %p\n", data);
106 TRACE("Not found\n");
110 HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
111 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
114 TRACE("(%p) : %s %p %d %d\n", This, debugstr_guid(refguid), pData, SizeOfData, Flags);
115 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
118 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
119 if (NULL == data) return E_OUTOFMEMORY;
121 data->tag = *refguid;
124 (*data)->uniquenessValue = This->uniquenessValue;
126 if (Flags & WINED3DSPD_IUNKNOWN) {
127 data->ptr.object = (LPUNKNOWN)pData;
128 data->size = sizeof(LPUNKNOWN);
129 IUnknown_AddRef(data->ptr.object);
133 data->ptr.data = HeapAlloc(GetProcessHeap(), 0, SizeOfData);
134 if (NULL == data->ptr.data) {
135 HeapFree(GetProcessHeap(), 0, data);
136 return E_OUTOFMEMORY;
138 data->size = SizeOfData;
139 memcpy(data->ptr.data, pData, SizeOfData);
141 list_add_tail(&This->resource.privateData, &data->entry);
145 /* I don't actually know how windows handles this case. The only
146 * reason I don't just call FreePrivateData is because I want to
147 * guarantee SetPrivateData working when using LPUNKNOWN or data
148 * that is no larger than the old data.
150 FIXME("Handle overwriting private data in SetPrivateData\n");
158 HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
159 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
162 TRACE("(%p) : %p %p %p\n", This, refguid, pData, pSizeOfData);
163 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
164 if (data == NULL) return WINED3DERR_NOTFOUND;
167 #if 0 /* This may not be right. */
168 if (((*data)->flags & WINED3DSPD_VOLATILE)
169 && (*data)->uniquenessValue != This->uniquenessValue)
170 return DDERR_EXPIRED;
172 if (*pSizeOfData < data->size) {
173 *pSizeOfData = data->size;
174 return WINED3DERR_MOREDATA;
177 if (data->flags & WINED3DSPD_IUNKNOWN) {
178 *(LPUNKNOWN *)pData = data->ptr.object;
179 IUnknown_AddRef(data->ptr.object);
182 memcpy(pData, data->ptr.data, data->size);
187 HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid) {
188 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
191 TRACE("(%p) : %s\n", This, debugstr_guid(refguid));
192 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
193 if (data == NULL) return WINED3DERR_NOTFOUND;
195 if (data->flags & WINED3DSPD_IUNKNOWN)
197 if (data->ptr.object != NULL)
198 IUnknown_Release(data->ptr.object);
200 HeapFree(GetProcessHeap(), 0, data->ptr.data);
202 list_remove(&data->entry);
204 HeapFree(GetProcessHeap(), 0, data);
209 /* Priority support is not implemented yet */
210 DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew) {
211 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
212 FIXME("(%p) : stub\n", This);
215 DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface) {
216 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
217 FIXME("(%p) : stub\n", This);
221 /* Preloading of resources is not supported yet */
222 void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface) {
223 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
224 FIXME("(%p) : stub\n", This);
227 WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface) {
228 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
229 TRACE("(%p) : returning %d\n", This, This->resource.resourceType);
230 return This->resource.resourceType;
233 HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent) {
234 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
235 IUnknown_AddRef(This->resource.parent);
236 *pParent = This->resource.parent;
240 void dumpResources(ResourceList *resources) {
241 ResourceList *iterator = resources;
244 FIXME("Leftover resource %p with type %d,%s\n", iterator->resource, IWineD3DResource_GetType(iterator->resource), debug_d3dresourcetype(IWineD3DResource_GetType(iterator->resource)));
245 iterator = iterator->next;
249 static const IWineD3DResourceVtbl IWineD3DResource_Vtbl =
252 IWineD3DResourceImpl_QueryInterface,
253 IWineD3DResourceImpl_AddRef,
254 IWineD3DResourceImpl_Release,
255 /* IWineD3DResource */
256 IWineD3DResourceImpl_GetParent,
257 IWineD3DResourceImpl_GetDevice,
258 IWineD3DResourceImpl_SetPrivateData,
259 IWineD3DResourceImpl_GetPrivateData,
260 IWineD3DResourceImpl_FreePrivateData,
261 IWineD3DResourceImpl_SetPriority,
262 IWineD3DResourceImpl_GetPriority,
263 IWineD3DResourceImpl_PreLoad,
264 IWineD3DResourceImpl_GetType