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_IWineD3DResource
)) {
37 IUnknown_AddRef(iface
);
44 ULONG WINAPI
IWineD3DResourceImpl_AddRef(IWineD3DResource
*iface
) {
45 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
46 ULONG ref
= InterlockedIncrement(&This
->resource
.ref
);
47 TRACE("(%p) : AddRef increasing from %ld\n", This
, ref
- 1);
51 ULONG WINAPI
IWineD3DResourceImpl_Release(IWineD3DResource
*iface
) {
52 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
53 ULONG ref
= InterlockedDecrement(&This
->resource
.ref
);
54 TRACE("(%p) : Releasing from %ld\n", This
, ref
+ 1);
56 IWineD3DResourceImpl_CleanUp(iface
);
57 HeapFree(GetProcessHeap(), 0, This
);
62 /* class static (not in vtable) */
63 void IWineD3DResourceImpl_CleanUp(IWineD3DResource
*iface
){
64 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
65 TRACE("(%p) Cleaning up resource\n", This
);
66 if (This
->resource
.pool
== D3DPOOL_DEFAULT
) {
67 TRACE("Decrementing device memory pool by %u\n", This
->resource
.size
);
68 globalChangeGlRam(-This
->resource
.size
);
71 HeapFree(GetProcessHeap(), 0, This
->resource
.allocatedMemory
);
72 This
->resource
.allocatedMemory
= 0;
74 if (This
->resource
.wineD3DDevice
!= NULL
) {
75 IWineD3DDevice_ResourceReleased((IWineD3DDevice
*)This
->resource
.wineD3DDevice
, iface
);
76 }/* NOTE: this is not really an error for systemmem resoruces */
80 /* IWineD3DResource Interface follow: */
81 HRESULT WINAPI
IWineD3DResourceImpl_GetDevice(IWineD3DResource
*iface
, IWineD3DDevice
** ppDevice
) {
82 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
83 TRACE("(%p) : returning %p\n", This
, This
->resource
.wineD3DDevice
);
84 *ppDevice
= (IWineD3DDevice
*) This
->resource
.wineD3DDevice
;
85 IWineD3DDevice_AddRef(*ppDevice
);
89 static PrivateData
** IWineD3DResourceImpl_FindPrivateData(IWineD3DResourceImpl
*This
,
93 for (data
= &This
->resource
.privateData
; *data
!= NULL
; data
= &(*data
)->next
)
95 if (IsEqualGUID(&(*data
)->tag
, tag
)) break;
100 HRESULT WINAPI
IWineD3DResourceImpl_SetPrivateData(IWineD3DResource
*iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
101 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
104 TRACE("(%p) : %p %p %ld %ld\n", This
, refguid
, pData
, SizeOfData
, Flags
);
105 data
= IWineD3DResourceImpl_FindPrivateData(This
, refguid
);
108 *data
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(**data
));
109 if (NULL
== *data
) return E_OUTOFMEMORY
;
111 (*data
)->tag
= *refguid
;
112 (*data
)->flags
= Flags
;
114 (*data
)->uniquenessValue
= This
->uniquenessValue
;
116 if (Flags
& D3DSPD_IUNKNOWN
) {
117 (*data
)->ptr
.object
= (LPUNKNOWN
)pData
;
118 (*data
)->size
= sizeof(LPUNKNOWN
);
119 IUnknown_AddRef((*data
)->ptr
.object
);
123 (*data
)->ptr
.data
= HeapAlloc(GetProcessHeap(), 0, SizeOfData
);
124 if (NULL
== (*data
)->ptr
.data
) {
125 HeapFree(GetProcessHeap(), 0, *data
);
126 return E_OUTOFMEMORY
;
130 (*data
)->next
= This
->resource
.privateData
;
131 This
->resource
.privateData
= *data
;
135 /* I don't actually know how windows handles this case. The only
136 * reason I don't just call FreePrivateData is because I want to
137 * guarantee SetPrivateData working when using LPUNKNOWN or data
138 * that is no larger than the old data. */
146 HRESULT WINAPI
IWineD3DResourceImpl_GetPrivateData(IWineD3DResource
*iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
147 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
150 TRACE("(%p) : %p %p %p\n", This
, refguid
, pData
, pSizeOfData
);
151 data
= IWineD3DResourceImpl_FindPrivateData(This
, refguid
);
152 if (*data
== NULL
) return D3DERR_NOTFOUND
;
155 #if 0 /* This may not be right. */
156 if (((*data
)->flags
& D3DSPD_VOLATILE
)
157 && (*data
)->uniquenessValue
!= This
->uniquenessValue
)
158 return DDERR_EXPIRED
;
160 if (*pSizeOfData
< (*data
)->size
) {
161 *pSizeOfData
= (*data
)->size
;
162 return D3DERR_MOREDATA
;
165 if ((*data
)->flags
& D3DSPD_IUNKNOWN
) {
166 *(LPUNKNOWN
*)pData
= (*data
)->ptr
.object
;
167 IUnknown_AddRef((*data
)->ptr
.object
);
170 memcpy(pData
, (*data
)->ptr
.data
, (*data
)->size
);
175 HRESULT WINAPI
IWineD3DResourceImpl_FreePrivateData(IWineD3DResource
*iface
, REFGUID refguid
) {
176 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
179 TRACE("(%p) : %p\n", This
, refguid
);
180 /* TODO: move this code off into a linked list class */
181 data
= IWineD3DResourceImpl_FindPrivateData(This
, refguid
);
182 if (*data
== NULL
) return D3DERR_NOTFOUND
;
184 *data
= (*data
)->next
;
186 if ((*data
)->flags
& D3DSPD_IUNKNOWN
)
188 if ((*data
)->ptr
.object
!= NULL
)
189 IUnknown_Release((*data
)->ptr
.object
);
191 HeapFree(GetProcessHeap(), 0, (*data
)->ptr
.data
);
194 HeapFree(GetProcessHeap(), 0, *data
);
199 /* Priority support is not implemented yet */
200 DWORD WINAPI
IWineD3DResourceImpl_SetPriority(IWineD3DResource
*iface
, DWORD PriorityNew
) {
201 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
202 FIXME("(%p) : stub\n", This
);
205 DWORD WINAPI
IWineD3DResourceImpl_GetPriority(IWineD3DResource
*iface
) {
206 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
207 FIXME("(%p) : stub\n", This
);
211 /* Preloading of resources is not supported yet */
212 void WINAPI
IWineD3DResourceImpl_PreLoad(IWineD3DResource
*iface
) {
213 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
214 FIXME("(%p) : stub\n", This
);
217 D3DRESOURCETYPE WINAPI
IWineD3DResourceImpl_GetType(IWineD3DResource
*iface
) {
218 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
219 TRACE("(%p) : returning %d\n", This
, This
->resource
.resourceType
);
220 return This
->resource
.resourceType
;
223 HRESULT WINAPI
IWineD3DResourceImpl_GetParent(IWineD3DResource
*iface
, IUnknown
**pParent
) {
224 IWineD3DResourceImpl
*This
= (IWineD3DResourceImpl
*)iface
;
225 IUnknown_AddRef(This
->resource
.parent
);
226 *pParent
= This
->resource
.parent
;
231 static const IWineD3DResourceVtbl IWineD3DResource_Vtbl
=
234 IWineD3DResourceImpl_QueryInterface
,
235 IWineD3DResourceImpl_AddRef
,
236 IWineD3DResourceImpl_Release
,
237 /* IWineD3DResource */
238 IWineD3DResourceImpl_GetParent
,
239 IWineD3DResourceImpl_GetDevice
,
240 IWineD3DResourceImpl_SetPrivateData
,
241 IWineD3DResourceImpl_GetPrivateData
,
242 IWineD3DResourceImpl_FreePrivateData
,
243 IWineD3DResourceImpl_SetPriority
,
244 IWineD3DResourceImpl_GetPriority
,
245 IWineD3DResourceImpl_PreLoad
,
246 IWineD3DResourceImpl_GetType