VirtualBox

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

Last change on this file since 30916 was 30916, checked in by vboxsync, 15 years ago

wddm/3d: Aero: fix gdi-backend textures update, avoid extra memcpy for sysmem textures Lock/Unlock

  • Property svn:eol-style set to native
File size: 8.9 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 if (size)
72 {
73 resource->heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + RESOURCE_ALIGNMENT);
74 if (!resource->heapMemory)
75 {
76 ERR("Out of memory!\n");
77 return WINED3DERR_OUTOFVIDEOMEMORY;
78 }
79 }
80 else
81 {
82 resource->heapMemory = NULL;
83 }
84 resource->allocatedMemory = (BYTE *)(((ULONG_PTR)resource->heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
85 }
86
87 /* Check that we have enough video ram left */
88 if (pool == WINED3DPOOL_DEFAULT)
89 {
90 if (size > IWineD3DDevice_GetAvailableTextureMem((IWineD3DDevice *)device))
91 {
92 ERR("Out of adapter memory\n");
93 HeapFree(GetProcessHeap(), 0, resource->heapMemory);
94 return WINED3DERR_OUTOFVIDEOMEMORY;
95 }
96 WineD3DAdapterChangeGLRam(device, size);
97 }
98
99 device_resource_add(device, iface);
100
101 return WINED3D_OK;
102}
103
104void resource_cleanup(IWineD3DResource *iface)
105{
106 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
107 struct list *e1, *e2;
108 PrivateData *data;
109 HRESULT hr;
110
111 TRACE("(%p) Cleaning up resource\n", This);
112 if (This->resource.pool == WINED3DPOOL_DEFAULT) {
113 TRACE("Decrementing device memory pool by %u\n", This->resource.size);
114 WineD3DAdapterChangeGLRam(This->resource.device, -This->resource.size);
115 }
116
117 LIST_FOR_EACH_SAFE(e1, e2, &This->resource.privateData) {
118 data = LIST_ENTRY(e1, PrivateData, entry);
119 hr = resource_free_private_data(iface, &data->tag);
120 if(hr != WINED3D_OK) {
121 ERR("Failed to free private data when destroying resource %p, hr = %08x\n", This, hr);
122 }
123 }
124
125 HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
126 This->resource.allocatedMemory = 0;
127 This->resource.heapMemory = 0;
128
129 if (This->resource.device) device_resource_released(This->resource.device, iface);
130}
131
132static PrivateData* resource_find_private_data(IWineD3DResourceImpl *This, REFGUID tag)
133{
134 PrivateData *data;
135 struct list *entry;
136
137 TRACE("Searching for private data %s\n", debugstr_guid(tag));
138 LIST_FOR_EACH(entry, &This->resource.privateData)
139 {
140 data = LIST_ENTRY(entry, PrivateData, entry);
141 if (IsEqualGUID(&data->tag, tag)) {
142 TRACE("Found %p\n", data);
143 return data;
144 }
145 }
146 TRACE("Not found\n");
147 return NULL;
148}
149
150HRESULT resource_set_private_data(IWineD3DResource *iface, REFGUID refguid,
151 const void *pData, DWORD SizeOfData, DWORD Flags)
152{
153 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
154 PrivateData *data;
155
156 TRACE("(%p) : %s %p %d %d\n", This, debugstr_guid(refguid), pData, SizeOfData, Flags);
157 resource_free_private_data(iface, refguid);
158
159 data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data));
160 if (NULL == data) return E_OUTOFMEMORY;
161
162 data->tag = *refguid;
163 data->flags = Flags;
164
165 if (Flags & WINED3DSPD_IUNKNOWN) {
166 if(SizeOfData != sizeof(IUnknown *)) {
167 WARN("IUnknown data with size %d, returning WINED3DERR_INVALIDCALL\n", SizeOfData);
168 HeapFree(GetProcessHeap(), 0, data);
169 return WINED3DERR_INVALIDCALL;
170 }
171 data->ptr.object = (LPUNKNOWN)pData;
172 data->size = sizeof(LPUNKNOWN);
173 IUnknown_AddRef(data->ptr.object);
174 }
175 else
176 {
177 data->ptr.data = HeapAlloc(GetProcessHeap(), 0, SizeOfData);
178 if (NULL == data->ptr.data) {
179 HeapFree(GetProcessHeap(), 0, data);
180 return E_OUTOFMEMORY;
181 }
182 data->size = SizeOfData;
183 memcpy(data->ptr.data, pData, SizeOfData);
184 }
185 list_add_tail(&This->resource.privateData, &data->entry);
186
187 return WINED3D_OK;
188}
189
190HRESULT resource_get_private_data(IWineD3DResource *iface, REFGUID refguid, void *pData, DWORD *pSizeOfData)
191{
192 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
193 PrivateData *data;
194
195 TRACE("(%p) : %p %p %p\n", This, refguid, pData, pSizeOfData);
196 data = resource_find_private_data(This, refguid);
197 if (data == NULL) return WINED3DERR_NOTFOUND;
198
199 if (*pSizeOfData < data->size) {
200 *pSizeOfData = data->size;
201 return WINED3DERR_MOREDATA;
202 }
203
204 if (data->flags & WINED3DSPD_IUNKNOWN) {
205 *(LPUNKNOWN *)pData = data->ptr.object;
206 if (((IWineD3DImpl *)This->resource.device->wined3d)->dxVersion != 7)
207 {
208 /* D3D8 and D3D9 addref the private data, DDraw does not. This can't be handled in
209 * ddraw because it doesn't know if the pointer returned is an IUnknown * or just a
210 * Blob
211 */
212 IUnknown_AddRef(data->ptr.object);
213 }
214 }
215 else {
216 memcpy(pData, data->ptr.data, data->size);
217 }
218
219 return WINED3D_OK;
220}
221HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID refguid)
222{
223 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
224 PrivateData *data;
225
226 TRACE("(%p) : %s\n", This, debugstr_guid(refguid));
227 data = resource_find_private_data(This, refguid);
228 if (data == NULL) return WINED3DERR_NOTFOUND;
229
230 if (data->flags & WINED3DSPD_IUNKNOWN)
231 {
232 if (data->ptr.object != NULL)
233 IUnknown_Release(data->ptr.object);
234 } else {
235 HeapFree(GetProcessHeap(), 0, data->ptr.data);
236 }
237 list_remove(&data->entry);
238
239 HeapFree(GetProcessHeap(), 0, data);
240
241 return WINED3D_OK;
242}
243
244DWORD resource_set_priority(IWineD3DResource *iface, DWORD PriorityNew)
245{
246 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
247 DWORD PriorityOld = This->resource.priority;
248 This->resource.priority = PriorityNew;
249 TRACE("(%p) : new priority %d, returning old priority %d\n", This, PriorityNew, PriorityOld );
250 return PriorityOld;
251}
252
253DWORD resource_get_priority(IWineD3DResource *iface)
254{
255 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
256 TRACE("(%p) : returning %d\n", This, This->resource.priority );
257 return This->resource.priority;
258}
259
260WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface)
261{
262 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
263 TRACE("(%p) : returning %d\n", This, This->resource.resourceType);
264 return This->resource.resourceType;
265}
266
267HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **pParent)
268{
269 IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
270 IUnknown_AddRef(This->resource.parent);
271 *pParent = This->resource.parent;
272 return WINED3D_OK;
273}
Note: See TracBrowser for help on using the repository browser.

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