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
;
71 TRACE("(%p) Cleaning up resource\n", This
);
72 if (This
->resource
.pool
== WINED3DPOOL_DEFAULT
) {
73 TRACE("Decrementing device memory pool by %u\n", This
->resource
.size
);
74 globalChangeGlRam(-This
->resource
.size
);
77 LIST_FOR_EACH_SAFE(e1
, e2
, &This
->resource
.privateData
) {
78 data
= LIST_ENTRY(e1
, PrivateData
, entry
);
79 hr
= IWineD3DResourceImpl_FreePrivateData(iface
, &data
->tag
);
80 if(hr
!= WINED3D_OK
) {
81 ERR("Failed to free private data when destroying resource %p, hr = %08x\n", This
, hr
);
85 HeapFree(GetProcessHeap(), 0, This
->resource
.allocatedMemory
);
86 This
->resource
.allocatedMemory
= 0;
88 if (This
->resource
.wineD3DDevice
!= NULL
) {
89 IWineD3DDevice_ResourceReleased((IWineD3DDevice
*)This
->resource
.wineD3DDevice
, iface
);
90 }/* NOTE: this is not really an error for systemmem resoruces */
94 /* IWineD3DResource Interface follow: */
95 HRESULT WINAPI
IWineD3DResourceImpl_GetDevice(IWineD3DResource
*iface
, IWineD3DDevice
** ppDevice
) {
96 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
97 TRACE("(%p) : returning %p\n", This
, This
->resource
.wineD3DDevice
);
98 *ppDevice
= (IWineD3DDevice
*) This
->resource
.wineD3DDevice
;
99 IWineD3DDevice_AddRef(*ppDevice
);
103 static PrivateData
* IWineD3DResourceImpl_FindPrivateData(IWineD3DResourceImpl
*This
,
109 TRACE("Searching for private data %s\n", debugstr_guid(tag
));
110 LIST_FOR_EACH(entry
, &This
->resource
.privateData
)
112 data
= LIST_ENTRY(entry
, PrivateData
, entry
);
113 if (IsEqualGUID(&data
->tag
, tag
)) {
114 TRACE("Found %p\n", data
);
118 TRACE("Not found\n");
122 HRESULT WINAPI
IWineD3DResourceImpl_SetPrivateData(IWineD3DResource
*iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
123 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
126 TRACE("(%p) : %s %p %d %d\n", This
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
127 IWineD3DResourceImpl_FreePrivateData(iface
, refguid
);
129 data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
));
130 if (NULL
== data
) return E_OUTOFMEMORY
;
132 data
->tag
= *refguid
;
135 (*data
)->uniquenessValue
= This
->uniquenessValue
;
137 if (Flags
& WINED3DSPD_IUNKNOWN
) {
138 if(SizeOfData
!= sizeof(IUnknown
*)) {
139 WARN("IUnknown data with size %d, returning WINED3DERR_INVALIDCALL\n", SizeOfData
);
140 return WINED3DERR_INVALIDCALL
;
142 data
->ptr
.object
= (LPUNKNOWN
)pData
;
143 data
->size
= sizeof(LPUNKNOWN
);
144 IUnknown_AddRef(data
->ptr
.object
);
148 data
->ptr
.data
= HeapAlloc(GetProcessHeap(), 0, SizeOfData
);
149 if (NULL
== data
->ptr
.data
) {
150 HeapFree(GetProcessHeap(), 0, data
);
151 return E_OUTOFMEMORY
;
153 data
->size
= SizeOfData
;
154 memcpy(data
->ptr
.data
, pData
, SizeOfData
);
156 list_add_tail(&This
->resource
.privateData
, &data
->entry
);
161 HRESULT WINAPI
IWineD3DResourceImpl_GetPrivateData(IWineD3DResource
*iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
162 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
165 TRACE("(%p) : %p %p %p\n", This
, refguid
, pData
, pSizeOfData
);
166 data
= IWineD3DResourceImpl_FindPrivateData(This
, refguid
);
167 if (data
== NULL
) return WINED3DERR_NOTFOUND
;
170 #if 0 /* This may not be right. */
171 if (((*data
)->flags
& WINED3DSPD_VOLATILE
)
172 && (*data
)->uniquenessValue
!= This
->uniquenessValue
)
173 return DDERR_EXPIRED
;
175 if (*pSizeOfData
< data
->size
) {
176 *pSizeOfData
= data
->size
;
177 return WINED3DERR_MOREDATA
;
180 if (data
->flags
& WINED3DSPD_IUNKNOWN
) {
181 *(LPUNKNOWN
*)pData
= data
->ptr
.object
;
182 if(((IWineD3DImpl
*) This
->resource
.wineD3DDevice
->wineD3D
)->dxVersion
!= 7) {
183 /* D3D8 and D3D9 addref the private data, DDraw does not. This can't be handled in
184 * ddraw because it doesn't know if the pointer returned is an IUnknown * or just a
187 IUnknown_AddRef(data
->ptr
.object
);
191 memcpy(pData
, data
->ptr
.data
, data
->size
);
196 HRESULT WINAPI
IWineD3DResourceImpl_FreePrivateData(IWineD3DResource
*iface
, REFGUID refguid
) {
197 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
200 TRACE("(%p) : %s\n", This
, debugstr_guid(refguid
));
201 data
= IWineD3DResourceImpl_FindPrivateData(This
, refguid
);
202 if (data
== NULL
) return WINED3DERR_NOTFOUND
;
204 if (data
->flags
& WINED3DSPD_IUNKNOWN
)
206 if (data
->ptr
.object
!= NULL
)
207 IUnknown_Release(data
->ptr
.object
);
209 HeapFree(GetProcessHeap(), 0, data
->ptr
.data
);
211 list_remove(&data
->entry
);
213 HeapFree(GetProcessHeap(), 0, data
);
218 /* Priority support is not implemented yet */
219 DWORD WINAPI
IWineD3DResourceImpl_SetPriority(IWineD3DResource
*iface
, DWORD PriorityNew
) {
220 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
221 FIXME("(%p) : stub\n", This
);
224 DWORD WINAPI
IWineD3DResourceImpl_GetPriority(IWineD3DResource
*iface
) {
225 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
226 FIXME("(%p) : stub\n", This
);
230 /* Preloading of resources is not supported yet */
231 void WINAPI
IWineD3DResourceImpl_PreLoad(IWineD3DResource
*iface
) {
232 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
233 FIXME("(%p) : stub\n", This
);
236 WINED3DRESOURCETYPE WINAPI
IWineD3DResourceImpl_GetType(IWineD3DResource
*iface
) {
237 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
238 TRACE("(%p) : returning %d\n", This
, This
->resource
.resourceType
);
239 return This
->resource
.resourceType
;
242 HRESULT WINAPI
IWineD3DResourceImpl_GetParent(IWineD3DResource
*iface
, IUnknown
**pParent
) {
243 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
244 IUnknown_AddRef(This
->resource
.parent
);
245 *pParent
= This
->resource
.parent
;
249 void dumpResources(ResourceList
*resources
) {
250 ResourceList
*iterator
= resources
;
253 FIXME("Leftover resource %p with type %d,%s\n", iterator
->resource
, IWineD3DResource_GetType(iterator
->resource
), debug_d3dresourcetype(IWineD3DResource_GetType(iterator
->resource
)));
254 iterator
= iterator
->next
;
258 static const IWineD3DResourceVtbl IWineD3DResource_Vtbl
=
261 IWineD3DResourceImpl_QueryInterface
,
262 IWineD3DResourceImpl_AddRef
,
263 IWineD3DResourceImpl_Release
,
264 /* IWineD3DResource */
265 IWineD3DResourceImpl_GetParent
,
266 IWineD3DResourceImpl_GetDevice
,
267 IWineD3DResourceImpl_SetPrivateData
,
268 IWineD3DResourceImpl_GetPrivateData
,
269 IWineD3DResourceImpl_FreePrivateData
,
270 IWineD3DResourceImpl_SetPriority
,
271 IWineD3DResourceImpl_GetPriority
,
272 IWineD3DResourceImpl_PreLoad
,
273 IWineD3DResourceImpl_GetType