VirtualBox

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

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

wddm/3d: auto-resize & fullscreen working for Aero

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