winebuild: Fixed index in module table for delayed imports.
[wine.git] / dlls / wined3d / resource.c
blob5a4b55066510ff80b243d9f057f6afd159dc705d
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "config.h"
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);
39 *ppobj = This;
40 return WINED3D_OK;
42 return E_NOINTERFACE;
45 ULONG WINAPI IWineD3DResourceImpl_AddRef(IWineD3DResource *iface) {
46 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
47 ULONG ref = InterlockedIncrement(&This->resource.ref);
48 TRACE("(%p) : AddRef increasing from %ld\n", This, ref - 1);
49 return ref;
52 ULONG WINAPI IWineD3DResourceImpl_Release(IWineD3DResource *iface) {
53 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
54 ULONG ref = InterlockedDecrement(&This->resource.ref);
55 TRACE("(%p) : Releasing from %ld\n", This, ref + 1);
56 if (ref == 0) {
57 IWineD3DResourceImpl_CleanUp(iface);
58 HeapFree(GetProcessHeap(), 0, This);
60 return ref;
63 /* class static (not in vtable) */
64 void IWineD3DResourceImpl_CleanUp(IWineD3DResource *iface){
65 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
66 TRACE("(%p) Cleaning up resource\n", This);
67 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
68 TRACE("Decrementing device memory pool by %u\n", This->resource.size);
69 globalChangeGlRam(-This->resource.size);
72 HeapFree(GetProcessHeap(), 0, This->resource.allocatedMemory);
73 This->resource.allocatedMemory = 0;
75 if (This->resource.wineD3DDevice != NULL) {
76 IWineD3DDevice_ResourceReleased((IWineD3DDevice *)This->resource.wineD3DDevice, iface);
77 }/* NOTE: this is not really an error for systemmem resoruces */
78 return;
81 /* IWineD3DResource Interface follow: */
82 HRESULT WINAPI IWineD3DResourceImpl_GetDevice(IWineD3DResource *iface, IWineD3DDevice** ppDevice) {
83 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
84 TRACE("(%p) : returning %p\n", This, This->resource.wineD3DDevice);
85 *ppDevice = (IWineD3DDevice *) This->resource.wineD3DDevice;
86 IWineD3DDevice_AddRef(*ppDevice);
87 return WINED3D_OK;
90 static PrivateData** IWineD3DResourceImpl_FindPrivateData(IWineD3DResourceImpl *This,
91 REFGUID tag)
93 PrivateData** data;
94 for (data = &This->resource.privateData; *data != NULL; data = &(*data)->next)
96 if (IsEqualGUID(&(*data)->tag, tag)) break;
98 return data;
101 HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
102 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
103 PrivateData **data;
105 TRACE("(%p) : %p %p %ld %ld\n", This, refguid, pData, SizeOfData, Flags);
106 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
107 if (*data == NULL)
109 *data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**data));
110 if (NULL == *data) return E_OUTOFMEMORY;
112 (*data)->tag = *refguid;
113 (*data)->flags = Flags;
114 #if 0
115 (*data)->uniquenessValue = This->uniquenessValue;
116 #endif
117 if (Flags & D3DSPD_IUNKNOWN) {
118 (*data)->ptr.object = (LPUNKNOWN)pData;
119 (*data)->size = sizeof(LPUNKNOWN);
120 IUnknown_AddRef((*data)->ptr.object);
122 else
124 (*data)->ptr.data = HeapAlloc(GetProcessHeap(), 0, SizeOfData);
125 if (NULL == (*data)->ptr.data) {
126 HeapFree(GetProcessHeap(), 0, *data);
127 return E_OUTOFMEMORY;
129 (*data)->size = SizeOfData;
130 memcpy((*data)->ptr.data, pData, SizeOfData);
132 /* link it in */
133 (*data)->next = This->resource.privateData;
134 This->resource.privateData = *data;
135 return WINED3D_OK;
137 } else {
138 /* I don't actually know how windows handles this case. The only
139 * reason I don't just call FreePrivateData is because I want to
140 * guarantee SetPrivateData working when using LPUNKNOWN or data
141 * that is no larger than the old data. */
142 return E_FAIL;
146 return WINED3D_OK;
149 HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
150 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
151 PrivateData **data;
153 TRACE("(%p) : %p %p %p\n", This, refguid, pData, pSizeOfData);
154 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
155 if (*data == NULL) return WINED3DERR_NOTFOUND;
158 #if 0 /* This may not be right. */
159 if (((*data)->flags & D3DSPD_VOLATILE)
160 && (*data)->uniquenessValue != This->uniquenessValue)
161 return DDERR_EXPIRED;
162 #endif
163 if (*pSizeOfData < (*data)->size) {
164 *pSizeOfData = (*data)->size;
165 return WINED3DERR_MOREDATA;
168 if ((*data)->flags & D3DSPD_IUNKNOWN) {
169 *(LPUNKNOWN *)pData = (*data)->ptr.object;
170 IUnknown_AddRef((*data)->ptr.object);
172 else {
173 memcpy(pData, (*data)->ptr.data, (*data)->size);
176 return WINED3D_OK;
178 HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid) {
179 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
180 PrivateData **data;
182 TRACE("(%p) : %p\n", This, refguid);
183 /* TODO: move this code off into a linked list class */
184 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
185 if (*data == NULL) return WINED3DERR_NOTFOUND;
187 *data = (*data)->next;
189 if ((*data)->flags & D3DSPD_IUNKNOWN)
191 if ((*data)->ptr.object != NULL)
192 IUnknown_Release((*data)->ptr.object);
193 } else {
194 HeapFree(GetProcessHeap(), 0, (*data)->ptr.data);
197 HeapFree(GetProcessHeap(), 0, *data);
199 return WINED3D_OK;
202 /* Priority support is not implemented yet */
203 DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew) {
204 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
205 FIXME("(%p) : stub\n", This);
206 return 0;
208 DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface) {
209 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
210 FIXME("(%p) : stub\n", This);
211 return 0;
214 /* Preloading of resources is not supported yet */
215 void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface) {
216 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
217 FIXME("(%p) : stub\n", This);
220 WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface) {
221 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
222 TRACE("(%p) : returning %d\n", This, This->resource.resourceType);
223 return This->resource.resourceType;
226 HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent) {
227 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
228 IUnknown_AddRef(This->resource.parent);
229 *pParent = This->resource.parent;
230 return WINED3D_OK;
233 void dumpResources(ResourceList *resources) {
234 ResourceList *iterator = resources;
236 while(iterator) {
237 FIXME("Leftover resource %p with type %d,%s\n", iterator->resource, IWineD3DResource_GetType(iterator->resource), debug_d3dresourcetype(IWineD3DResource_GetType(iterator->resource)));
238 iterator = iterator->next;
242 static const IWineD3DResourceVtbl IWineD3DResource_Vtbl =
244 /* IUnknown */
245 IWineD3DResourceImpl_QueryInterface,
246 IWineD3DResourceImpl_AddRef,
247 IWineD3DResourceImpl_Release,
248 /* IWineD3DResource */
249 IWineD3DResourceImpl_GetParent,
250 IWineD3DResourceImpl_GetDevice,
251 IWineD3DResourceImpl_SetPrivateData,
252 IWineD3DResourceImpl_GetPrivateData,
253 IWineD3DResourceImpl_FreePrivateData,
254 IWineD3DResourceImpl_SetPriority,
255 IWineD3DResourceImpl_GetPriority,
256 IWineD3DResourceImpl_PreLoad,
257 IWineD3DResourceImpl_GetType