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,
95 for (data = &This->resource.privateData; *data != NULL; data = &(*data)->next)
97 if (IsEqualGUID(&(*data)->tag, tag)) break;
102 HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
103 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
106 TRACE("(%p) : %p %p %d %d\n", This, refguid, pData, SizeOfData, Flags);
107 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
110 *data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**data));
111 if (NULL == *data) return E_OUTOFMEMORY;
113 (*data)->tag = *refguid;
114 (*data)->flags = Flags;
116 (*data)->uniquenessValue = This->uniquenessValue;
118 if (Flags & WINED3DSPD_IUNKNOWN) {
119 (*data)->ptr.object = (LPUNKNOWN)pData;
120 (*data)->size = sizeof(LPUNKNOWN);
121 IUnknown_AddRef((*data)->ptr.object);
125 (*data)->ptr.data = HeapAlloc(GetProcessHeap(), 0, SizeOfData);
126 if (NULL == (*data)->ptr.data) {
127 HeapFree(GetProcessHeap(), 0, *data);
128 return E_OUTOFMEMORY;
130 (*data)->size = SizeOfData;
131 memcpy((*data)->ptr.data, pData, SizeOfData);
134 (*data)->next = This->resource.privateData;
135 This->resource.privateData = *data;
139 /* I don't actually know how windows handles this case. The only
140 * reason I don't just call FreePrivateData is because I want to
141 * guarantee SetPrivateData working when using LPUNKNOWN or data
142 * that is no larger than the old data. */
150 HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
151 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
154 TRACE("(%p) : %p %p %p\n", This, refguid, pData, pSizeOfData);
155 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
156 if (*data == NULL) return WINED3DERR_NOTFOUND;
159 #if 0 /* This may not be right. */
160 if (((*data)->flags & WINED3DSPD_VOLATILE)
161 && (*data)->uniquenessValue != This->uniquenessValue)
162 return DDERR_EXPIRED;
164 if (*pSizeOfData < (*data)->size) {
165 *pSizeOfData = (*data)->size;
166 return WINED3DERR_MOREDATA;
169 if ((*data)->flags & WINED3DSPD_IUNKNOWN) {
170 *(LPUNKNOWN *)pData = (*data)->ptr.object;
171 IUnknown_AddRef((*data)->ptr.object);
174 memcpy(pData, (*data)->ptr.data, (*data)->size);
179 HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid) {
180 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
183 TRACE("(%p) : %p\n", This, refguid);
184 /* TODO: move this code off into a linked list class */
185 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
186 if (*data == NULL) return WINED3DERR_NOTFOUND;
188 *data = (*data)->next;
190 if ((*data)->flags & WINED3DSPD_IUNKNOWN)
192 if ((*data)->ptr.object != NULL)
193 IUnknown_Release((*data)->ptr.object);
195 HeapFree(GetProcessHeap(), 0, (*data)->ptr.data);
198 HeapFree(GetProcessHeap(), 0, *data);
203 /* Priority support is not implemented yet */
204 DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew) {
205 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
206 FIXME("(%p) : stub\n", This);
209 DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface) {
210 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
211 FIXME("(%p) : stub\n", This);
215 /* Preloading of resources is not supported yet */
216 void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface) {
217 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
218 FIXME("(%p) : stub\n", This);
221 WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface) {
222 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
223 TRACE("(%p) : returning %d\n", This, This->resource.resourceType);
224 return This->resource.resourceType;
227 HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent) {
228 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
229 IUnknown_AddRef(This->resource.parent);
230 *pParent = This->resource.parent;
234 void dumpResources(ResourceList *resources) {
235 ResourceList *iterator = resources;
238 FIXME("Leftover resource %p with type %d,%s\n", iterator->resource, IWineD3DResource_GetType(iterator->resource), debug_d3dresourcetype(IWineD3DResource_GetType(iterator->resource)));
239 iterator = iterator->next;
243 static const IWineD3DResourceVtbl IWineD3DResource_Vtbl =
246 IWineD3DResourceImpl_QueryInterface,
247 IWineD3DResourceImpl_AddRef,
248 IWineD3DResourceImpl_Release,
249 /* IWineD3DResource */
250 IWineD3DResourceImpl_GetParent,
251 IWineD3DResourceImpl_GetDevice,
252 IWineD3DResourceImpl_SetPrivateData,
253 IWineD3DResourceImpl_GetPrivateData,
254 IWineD3DResourceImpl_FreePrivateData,
255 IWineD3DResourceImpl_SetPriority,
256 IWineD3DResourceImpl_GetPriority,
257 IWineD3DResourceImpl_PreLoad,
258 IWineD3DResourceImpl_GetType