VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c@ 31936

Last change on this file since 31936 was 31936, checked in by vboxsync, 14 years ago

wine: shared rc support more impl + fixes

  • Property svn:eol-style set to native
File size: 9.2 KB
Line 
1/*
2 * IWineD3DResource Implementation
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2009 Henri Verbeet for CodeWeavers
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25/*
26 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
27 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
28 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
29 * a choice of LGPL license versions is made available with the language indicating
30 * that LGPLv2 or any later version may be used, or where a choice of which version
31 * of the LGPL is applied is otherwise unspecified.
32 */
33
34#include "config.h"
35#include "wined3d_private.h"
36
37WINE_DEFAULT_DEBUG_CHANNEL(d3d);
38
39HRESULT resource_init(IWineD3DResource *iface, WINED3DRESOURCETYPE resource_type,
40 IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
41 WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
42#ifdef VBOXWDDM
43 , HANDLE *shared_handle
44 , void *pvClientMem
45#endif
46 )
47{
48 struct IWineD3DResourceClass *resource = &((IWineD3DResourceImpl *)iface)->resource;
49
50 resource->device = device;
51 resource->parent = parent;
52 resource->resourceType = resource_type;
53 resource->ref = 1;
54 resource->pool = pool;
55 resource->format_desc = format_desc;
56 resource->usage = usage;
57 resource->size = size;
58 resource->priority = 0;
59 resource->parent_ops = parent_ops;
60 list_init(&resource->privateData);
61
62#ifdef VBOXWDDM
63 if (pool == WINED3DPOOL_SYSTEMMEM && pvClientMem)
64 {
65 resource->allocatedMemory = pvClientMem;
66 resource->heapMemory = NULL;
67 }
68 else
69#endif
70 {
71#ifdef VBOXWDDM
72 if (pool == WINED3DPOOL_DEFAULT && shared_handle)
73 {
74 resource->sharerc_handle = *shared_handle;
75 resource->sharerc_flags = VBOXSHRC_F_SHARED;
76 if (*shared_handle)
77 resource->sharerc_flags |= VBOXSHRC_F_SHARED_OPENED;
78 }
79#endif
80 if (size)
81 {
82 resource->heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + RESOURCE_ALIGNMENT);
83 if (!resource->heapMemory)
84 {
85 ERR("Out of memory!\n");
86 return WINED3DERR_OUTOFVIDEOMEMORY;
87 }
88 }
89 else
90 {
91 resource->heapMemory = NULL;
92 }
93 resource->allocatedMemory = (BYTE *)(((ULONG_PTR)resource->heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
94 }
95
96 /* Check that we have enough video ram left */
97 if (pool == WINED3DPOOL_DEFAULT)
98 {
99 if (size > IWineD3DDevice_GetAvailableTextureMem((IWineD3DDevice *)device))
100 {
101 ERR("Out of adapter memory\n");
102 HeapFree(GetProcessHeap(), 0, resource->heapMemory);
103 return WINED3DERR_OUTOFVIDEOMEMORY;
104 }
105 WineD3DAdapterChangeGLRam(device, size);
106 }
107
108 device_resource_add(device, iface);
109
110 return WINED3D_OK;
111}
112
113void resource_cleanup(IWineD3DResource *iface)
114{
115 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
116 struct list *e1, *e2;
117 PrivateData *data;
118 HRESULT hr;
119
120 TRACE("(%p) Cleaning up resource\n", This);
121 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
122 TRACE("Decrementing device memory pool by %u\n", This->resource.size);
123 WineD3DAdapterChangeGLRam(This->resource.device, -This->resource.size);
124 }
125
126 LIST_FOR_EACH_SAFE(e1, e2, &This->resource.privateData) {
127 data = LIST_ENTRY(e1, PrivateData, entry);
128 hr = resource_free_private_data(iface, &data->tag);
129 if(hr != WINED3D_OK) {
130 ERR("Failed to free private data when destroying resource %p, hr = %08x\n", This, hr);
131 }
132 }
133
134 HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
135 This->resource.allocatedMemory = 0;
136 This->resource.heapMemory = 0;
137
138 if (This->resource.device) device_resource_released(This->resource.device, iface);
139}
140
141static PrivateData* resource_find_private_data(IWineD3DResourceImpl *This, REFGUID tag)
142{
143 PrivateData *data;
144 struct list *entry;
145
146 TRACE("Searching for private data %s\n", debugstr_guid(tag));
147 LIST_FOR_EACH(entry, &This->resource.privateData)
148 {
149 data = LIST_ENTRY(entry, PrivateData, entry);
150 if (IsEqualGUID(&data->tag, tag)) {
151 TRACE("Found %p\n", data);
152 return data;
153 }
154 }
155 TRACE("Not found\n");
156 return NULL;
157}
158
159HRESULT resource_set_private_data(IWineD3DResource *iface, REFGUID refguid,
160 const void *pData, DWORD SizeOfData, DWORD Flags)
161{
162 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
163 PrivateData *data;
164
165 TRACE("(%p) : %s %p %d %d\n", This, debugstr_guid(refguid), pData, SizeOfData, Flags);
166 resource_free_private_data(iface, refguid);
167
168 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
169 if (NULL == data) return E_OUTOFMEMORY;
170
171 data->tag = *refguid;
172 data->flags = Flags;
173
174 if (Flags & WINED3DSPD_IUNKNOWN) {
175 if(SizeOfData != sizeof(IUnknown *)) {
176 WARN("IUnknown data with size %d, returning WINED3DERR_INVALIDCALL\n", SizeOfData);
177 HeapFree(GetProcessHeap(), 0, data);
178 return WINED3DERR_INVALIDCALL;
179 }
180 data->ptr.object = (LPUNKNOWN)pData;
181 data->size = sizeof(LPUNKNOWN);
182 IUnknown_AddRef(data->ptr.object);
183 }
184 else
185 {
186 data->ptr.data = HeapAlloc(GetProcessHeap(), 0, SizeOfData);
187 if (NULL == data->ptr.data) {
188 HeapFree(GetProcessHeap(), 0, data);
189 return E_OUTOFMEMORY;
190 }
191 data->size = SizeOfData;
192 memcpy(data->ptr.data, pData, SizeOfData);
193 }
194 list_add_tail(&This->resource.privateData, &data->entry);
195
196 return WINED3D_OK;
197}
198
199HRESULT resource_get_private_data(IWineD3DResource *iface, REFGUID refguid, void *pData, DWORD *pSizeOfData)
200{
201 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
202 PrivateData *data;
203
204 TRACE("(%p) : %p %p %p\n", This, refguid, pData, pSizeOfData);
205 data = resource_find_private_data(This, refguid);
206 if (data == NULL) return WINED3DERR_NOTFOUND;
207
208 if (*pSizeOfData < data->size) {
209 *pSizeOfData = data->size;
210 return WINED3DERR_MOREDATA;
211 }
212
213 if (data->flags & WINED3DSPD_IUNKNOWN) {
214 *(LPUNKNOWN *)pData = data->ptr.object;
215 if (((IWineD3DImpl *)This->resource.device->wined3d)->dxVersion != 7)
216 {
217 /* D3D8 and D3D9 addref the private data, DDraw does not. This can't be handled in
218 * ddraw because it doesn't know if the pointer returned is an IUnknown * or just a
219 * Blob
220 */
221 IUnknown_AddRef(data->ptr.object);
222 }
223 }
224 else {
225 memcpy(pData, data->ptr.data, data->size);
226 }
227
228 return WINED3D_OK;
229}
230HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID refguid)
231{
232 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
233 PrivateData *data;
234
235 TRACE("(%p) : %s\n", This, debugstr_guid(refguid));
236 data = resource_find_private_data(This, refguid);
237 if (data == NULL) return WINED3DERR_NOTFOUND;
238
239 if (data->flags & WINED3DSPD_IUNKNOWN)
240 {
241 if (data->ptr.object != NULL)
242 IUnknown_Release(data->ptr.object);
243 } else {
244 HeapFree(GetProcessHeap(), 0, data->ptr.data);
245 }
246 list_remove(&data->entry);
247
248 HeapFree(GetProcessHeap(), 0, data);
249
250 return WINED3D_OK;
251}
252
253DWORD resource_set_priority(IWineD3DResource *iface, DWORD PriorityNew)
254{
255 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
256 DWORD PriorityOld = This->resource.priority;
257 This->resource.priority = PriorityNew;
258 TRACE("(%p) : new priority %d, returning old priority %d\n", This, PriorityNew, PriorityOld );
259 return PriorityOld;
260}
261
262DWORD resource_get_priority(IWineD3DResource *iface)
263{
264 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
265 TRACE("(%p) : returning %d\n", This, This->resource.priority );
266 return This->resource.priority;
267}
268
269WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface)
270{
271 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
272 TRACE("(%p) : returning %d\n", This, This->resource.resourceType);
273 return This->resource.resourceType;
274}
275
276HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **pParent)
277{
278 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
279 IUnknown_AddRef(This->resource.parent);
280 *pParent = This->resource.parent;
281 return WINED3D_OK;
282}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette