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
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);
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);
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);
57 IWineD3DResourceImpl_CleanUp(iface);
58 HeapFree(GetProcessHeap(), 0, This);
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 */
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);
90 static PrivateData** IWineD3DResourceImpl_FindPrivateData(IWineD3DResourceImpl *This,
94 for (data = &This->resource.privateData; *data != NULL; data = &(*data)->next)
96 if (IsEqualGUID(&(*data)->tag, tag)) break;
101 HRESULT WINAPI IWineD3DResourceImpl_SetPrivateData(IWineD3DResource *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
102 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
105 TRACE("(%p) : %p %p %ld %ld\n", This, refguid, pData, SizeOfData, Flags);
106 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
109 *data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(**data));
110 if (NULL == *data) return E_OUTOFMEMORY;
112 (*data)->tag = *refguid;
113 (*data)->flags = Flags;
115 (*data)->uniquenessValue = This->uniquenessValue;
117 if (Flags & D3DSPD_IUNKNOWN) {
118 (*data)->ptr.object = (LPUNKNOWN)pData;
119 (*data)->size = sizeof(LPUNKNOWN);
120 IUnknown_AddRef((*data)->ptr.object);
124 (*data)->ptr.data = HeapAlloc(GetProcessHeap(), 0, SizeOfData);
125 if (NULL == (*data)->ptr.data) {
126 HeapFree(GetProcessHeap(), 0, *data);
127 return E_OUTOFMEMORY;
131 (*data)->next = This->resource.privateData;
132 This->resource.privateData = *data;
136 /* I don't actually know how windows handles this case. The only
137 * reason I don't just call FreePrivateData is because I want to
138 * guarantee SetPrivateData working when using LPUNKNOWN or data
139 * that is no larger than the old data. */
147 HRESULT WINAPI IWineD3DResourceImpl_GetPrivateData(IWineD3DResource *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
148 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
151 TRACE("(%p) : %p %p %p\n", This, refguid, pData, pSizeOfData);
152 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
153 if (*data == NULL) return WINED3DERR_NOTFOUND;
156 #if 0 /* This may not be right. */
157 if (((*data)->flags & D3DSPD_VOLATILE)
158 && (*data)->uniquenessValue != This->uniquenessValue)
159 return DDERR_EXPIRED;
161 if (*pSizeOfData < (*data)->size) {
162 *pSizeOfData = (*data)->size;
163 return WINED3DERR_MOREDATA;
166 if ((*data)->flags & D3DSPD_IUNKNOWN) {
167 *(LPUNKNOWN *)pData = (*data)->ptr.object;
168 IUnknown_AddRef((*data)->ptr.object);
171 memcpy(pData, (*data)->ptr.data, (*data)->size);
176 HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REFGUID refguid) {
177 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
180 TRACE("(%p) : %p\n", This, refguid);
181 /* TODO: move this code off into a linked list class */
182 data = IWineD3DResourceImpl_FindPrivateData(This, refguid);
183 if (*data == NULL) return WINED3DERR_NOTFOUND;
185 *data = (*data)->next;
187 if ((*data)->flags & D3DSPD_IUNKNOWN)
189 if ((*data)->ptr.object != NULL)
190 IUnknown_Release((*data)->ptr.object);
192 HeapFree(GetProcessHeap(), 0, (*data)->ptr.data);
195 HeapFree(GetProcessHeap(), 0, *data);
200 /* Priority support is not implemented yet */
201 DWORD WINAPI IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew) {
202 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
203 FIXME("(%p) : stub\n", This);
206 DWORD WINAPI IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface) {
207 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
208 FIXME("(%p) : stub\n", This);
212 /* Preloading of resources is not supported yet */
213 void WINAPI IWineD3DResourceImpl_PreLoad(IWineD3DResource *iface) {
214 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
215 FIXME("(%p) : stub\n", This);
218 WINED3DRESOURCETYPE WINAPI IWineD3DResourceImpl_GetType(IWineD3DResource *iface) {
219 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
220 TRACE("(%p) : returning %d\n", This, This->resource.resourceType);
221 return This->resource.resourceType;
224 HRESULT WINAPI IWineD3DResourceImpl_GetParent(IWineD3DResource *iface, IUnknown **pParent) {
225 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
226 IUnknown_AddRef(This->resource.parent);
227 *pParent = This->resource.parent;
232 static const IWineD3DResourceVtbl IWineD3DResource_Vtbl =
235 IWineD3DResourceImpl_QueryInterface,
236 IWineD3DResourceImpl_AddRef,
237 IWineD3DResourceImpl_Release,
238 /* IWineD3DResource */
239 IWineD3DResourceImpl_GetParent,
240 IWineD3DResourceImpl_GetDevice,
241 IWineD3DResourceImpl_SetPrivateData,
242 IWineD3DResourceImpl_GetPrivateData,
243 IWineD3DResourceImpl_FreePrivateData,
244 IWineD3DResourceImpl_SetPriority,
245 IWineD3DResourceImpl_GetPriority,
246 IWineD3DResourceImpl_PreLoad,
247 IWineD3DResourceImpl_GetType