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 void resource_cleanup(IWineD3DResource
*iface
)
32 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
37 TRACE("(%p) Cleaning up resource\n", This
);
38 if (This
->resource
.pool
== WINED3DPOOL_DEFAULT
) {
39 TRACE("Decrementing device memory pool by %u\n", This
->resource
.size
);
40 WineD3DAdapterChangeGLRam(This
->resource
.wineD3DDevice
, -This
->resource
.size
);
43 LIST_FOR_EACH_SAFE(e1
, e2
, &This
->resource
.privateData
) {
44 data
= LIST_ENTRY(e1
, PrivateData
, entry
);
45 hr
= resource_free_private_data(iface
, &data
->tag
);
46 if(hr
!= WINED3D_OK
) {
47 ERR("Failed to free private data when destroying resource %p, hr = %08x\n", This
, hr
);
51 HeapFree(GetProcessHeap(), 0, This
->resource
.heapMemory
);
52 This
->resource
.allocatedMemory
= 0;
53 This
->resource
.heapMemory
= 0;
55 if (This
->resource
.wineD3DDevice
!= NULL
) {
56 IWineD3DDevice_ResourceReleased((IWineD3DDevice
*)This
->resource
.wineD3DDevice
, iface
);
57 }/* NOTE: this is not really an error for system memory resources */
61 HRESULT
resource_get_device(IWineD3DResource
*iface
, IWineD3DDevice
** ppDevice
)
63 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
64 TRACE("(%p) : returning %p\n", This
, This
->resource
.wineD3DDevice
);
65 *ppDevice
= (IWineD3DDevice
*) This
->resource
.wineD3DDevice
;
66 IWineD3DDevice_AddRef(*ppDevice
);
70 static PrivateData
* resource_find_private_data(IWineD3DResourceImpl
*This
, REFGUID tag
)
75 TRACE("Searching for private data %s\n", debugstr_guid(tag
));
76 LIST_FOR_EACH(entry
, &This
->resource
.privateData
)
78 data
= LIST_ENTRY(entry
, PrivateData
, entry
);
79 if (IsEqualGUID(&data
->tag
, tag
)) {
80 TRACE("Found %p\n", data
);
88 HRESULT
resource_set_private_data(IWineD3DResource
*iface
, REFGUID refguid
,
89 const void *pData
, DWORD SizeOfData
, DWORD Flags
)
91 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
94 TRACE("(%p) : %s %p %d %d\n", This
, debugstr_guid(refguid
), pData
, SizeOfData
, Flags
);
95 resource_free_private_data(iface
, refguid
);
97 data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
));
98 if (NULL
== data
) return E_OUTOFMEMORY
;
100 data
->tag
= *refguid
;
103 if (Flags
& WINED3DSPD_IUNKNOWN
) {
104 if(SizeOfData
!= sizeof(IUnknown
*)) {
105 WARN("IUnknown data with size %d, returning WINED3DERR_INVALIDCALL\n", SizeOfData
);
106 HeapFree(GetProcessHeap(), 0, data
);
107 return WINED3DERR_INVALIDCALL
;
109 data
->ptr
.object
= (LPUNKNOWN
)pData
;
110 data
->size
= sizeof(LPUNKNOWN
);
111 IUnknown_AddRef(data
->ptr
.object
);
115 data
->ptr
.data
= HeapAlloc(GetProcessHeap(), 0, SizeOfData
);
116 if (NULL
== data
->ptr
.data
) {
117 HeapFree(GetProcessHeap(), 0, data
);
118 return E_OUTOFMEMORY
;
120 data
->size
= SizeOfData
;
121 memcpy(data
->ptr
.data
, pData
, SizeOfData
);
123 list_add_tail(&This
->resource
.privateData
, &data
->entry
);
128 HRESULT
resource_get_private_data(IWineD3DResource
*iface
, REFGUID refguid
, void *pData
, DWORD
*pSizeOfData
)
130 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
133 TRACE("(%p) : %p %p %p\n", This
, refguid
, pData
, pSizeOfData
);
134 data
= resource_find_private_data(This
, refguid
);
135 if (data
== NULL
) return WINED3DERR_NOTFOUND
;
137 if (*pSizeOfData
< data
->size
) {
138 *pSizeOfData
= data
->size
;
139 return WINED3DERR_MOREDATA
;
142 if (data
->flags
& WINED3DSPD_IUNKNOWN
) {
143 *(LPUNKNOWN
*)pData
= data
->ptr
.object
;
144 if(((IWineD3DImpl
*) This
->resource
.wineD3DDevice
->wineD3D
)->dxVersion
!= 7) {
145 /* D3D8 and D3D9 addref the private data, DDraw does not. This can't be handled in
146 * ddraw because it doesn't know if the pointer returned is an IUnknown * or just a
149 IUnknown_AddRef(data
->ptr
.object
);
153 memcpy(pData
, data
->ptr
.data
, data
->size
);
158 HRESULT
resource_free_private_data(IWineD3DResource
*iface
, REFGUID refguid
)
160 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
163 TRACE("(%p) : %s\n", This
, debugstr_guid(refguid
));
164 data
= resource_find_private_data(This
, refguid
);
165 if (data
== NULL
) return WINED3DERR_NOTFOUND
;
167 if (data
->flags
& WINED3DSPD_IUNKNOWN
)
169 if (data
->ptr
.object
!= NULL
)
170 IUnknown_Release(data
->ptr
.object
);
172 HeapFree(GetProcessHeap(), 0, data
->ptr
.data
);
174 list_remove(&data
->entry
);
176 HeapFree(GetProcessHeap(), 0, data
);
181 DWORD
resource_set_priority(IWineD3DResource
*iface
, DWORD PriorityNew
)
183 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
184 DWORD PriorityOld
= This
->resource
.priority
;
185 This
->resource
.priority
= PriorityNew
;
186 TRACE("(%p) : new priority %d, returning old priority %d\n", This
, PriorityNew
, PriorityOld
);
190 DWORD
resource_get_priority(IWineD3DResource
*iface
)
192 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
193 TRACE("(%p) : returning %d\n", This
, This
->resource
.priority
);
194 return This
->resource
.priority
;
197 WINED3DRESOURCETYPE
resource_get_type(IWineD3DResource
*iface
)
199 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
200 TRACE("(%p) : returning %d\n", This
, This
->resource
.resourceType
);
201 return This
->resource
.resourceType
;
204 HRESULT
resource_get_parent(IWineD3DResource
*iface
, IUnknown
**pParent
)
206 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
207 IUnknown_AddRef(This
->resource
.parent
);
208 *pParent
= This
->resource
.parent
;
212 void dumpResources(struct list
*list
) {
213 IWineD3DResourceImpl
*resource
;
215 LIST_FOR_EACH_ENTRY(resource
, list
, IWineD3DResourceImpl
, resource
.resource_list_entry
) {
216 FIXME("Leftover resource %p with type %d,%s\n", resource
, IWineD3DResource_GetType((IWineD3DResource
*) resource
), debug_d3dresourcetype(IWineD3DResource_GetType((IWineD3DResource
*) resource
)));