VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/resource.c@ 63490

Last change on this file since 63490 was 63025, checked in by vboxsync, 8 years ago

GA/NT/Graphics: warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1/*
2 * Copyright 2002-2004 Jason Edmeades
3 * Copyright 2003-2004 Raphael Junqueira
4 * Copyright 2004 Christian Costa
5 * Copyright 2005 Oliver Stieber
6 * Copyright 2009-2010 Henri Verbeet for CodeWeavers
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23/*
24 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33#include "wine/port.h"
34#include "wined3d_private.h"
35
36WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37
38struct private_data
39{
40 struct list entry;
41
42 GUID tag;
43 DWORD flags; /* DDSPD_* */
44
45 union
46 {
47 void *data;
48 IUnknown *object;
49 } ptr;
50
51 DWORD size;
52};
53
54static DWORD resource_access_from_pool(enum wined3d_pool pool)
55{
56 switch (pool)
57 {
58 case WINED3D_POOL_DEFAULT:
59 return WINED3D_RESOURCE_ACCESS_GPU;
60
61 case WINED3D_POOL_MANAGED:
62 return WINED3D_RESOURCE_ACCESS_GPU | WINED3D_RESOURCE_ACCESS_CPU;
63
64 case WINED3D_POOL_SYSTEM_MEM:
65 return WINED3D_RESOURCE_ACCESS_CPU;
66
67 case WINED3D_POOL_SCRATCH:
68 return WINED3D_RESOURCE_ACCESS_SCRATCH;
69
70 default:
71 FIXME("Unhandled pool %#x.\n", pool);
72 return 0;
73 }
74}
75
76static void resource_check_usage(DWORD usage)
77{
78 static const DWORD handled = WINED3DUSAGE_RENDERTARGET
79 | WINED3DUSAGE_DEPTHSTENCIL
80 | WINED3DUSAGE_DYNAMIC
81 | WINED3DUSAGE_AUTOGENMIPMAP
82 | WINED3DUSAGE_STATICDECL
83 | WINED3DUSAGE_OVERLAY;
84
85 if (usage & ~handled)
86 FIXME("Unhandled usage flags %#x.\n", usage & ~handled);
87}
88
89HRESULT resource_init(struct wined3d_resource *resource, struct wined3d_device *device,
90 enum wined3d_resource_type type, const struct wined3d_format *format,
91 enum wined3d_multisample_type multisample_type, UINT multisample_quality,
92 DWORD usage, enum wined3d_pool pool, UINT width, UINT height, UINT depth, UINT size,
93 void *parent, const struct wined3d_parent_ops *parent_ops,
94 const struct wined3d_resource_ops *resource_ops
95#ifdef VBOX_WITH_WDDM
96 , HANDLE *shared_handle
97 , void *pvClientMem
98#endif
99 )
100{
101#ifndef VBOX_WITH_WDDM
102 const struct wined3d *d3d = device->wined3d;
103#endif
104
105 resource->ref = 1;
106 resource->device = device;
107 resource->type = type;
108 resource->format = format;
109 resource->multisample_type = multisample_type;
110 resource->multisample_quality = multisample_quality;
111 resource->usage = usage;
112 resource->pool = pool;
113 resource->access_flags = resource_access_from_pool(pool);
114 if (usage & WINED3DUSAGE_DYNAMIC)
115 resource->access_flags |= WINED3D_RESOURCE_ACCESS_CPU;
116 resource->width = width;
117 resource->height = height;
118 resource->depth = depth;
119 resource->size = size;
120 resource->priority = 0;
121 resource->parent = parent;
122 resource->parent_ops = parent_ops;
123 resource->resource_ops = resource_ops;
124 list_init(&resource->privateData);
125
126 resource_check_usage(usage);
127
128#ifdef VBOX_WITH_WDDM
129 resource->sharerc_handle = 0;
130 resource->sharerc_flags = 0;
131 resource->sharerc_locks = 0;
132 if (pool == WINED3D_POOL_SYSTEM_MEM && pvClientMem)
133 {
134 resource->allocatedMemory = pvClientMem;
135 resource->heapMemory = NULL;
136 }
137 else
138#endif
139 {
140#ifdef VBOX_WITH_WDDM
141 if (pool == WINED3D_POOL_DEFAULT && shared_handle)
142 {
143 resource->sharerc_handle = (DWORD)*shared_handle;
144 resource->sharerc_flags = VBOXSHRC_F_SHARED;
145 if (*shared_handle)
146 resource->sharerc_flags |= VBOXSHRC_F_SHARED_OPENED;
147 }
148#endif
149
150 if (size)
151 {
152 resource->heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + RESOURCE_ALIGNMENT);
153 if (!resource->heapMemory)
154 {
155 ERR("Out of memory!\n");
156 return WINED3DERR_OUTOFVIDEOMEMORY;
157 }
158 }
159 else
160 {
161 resource->heapMemory = NULL;
162 }
163 resource->allocatedMemory = (BYTE *)(((ULONG_PTR)resource->heapMemory
164 + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
165 }
166
167#ifndef VBOX_WITH_WDDM
168 /* Check that we have enough video ram left */
169 if (pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
170 {
171 if (size > wined3d_device_get_available_texture_mem(device))
172 {
173 ERR("Out of adapter memory\n");
174 HeapFree(GetProcessHeap(), 0, resource->heapMemory);
175 return WINED3DERR_OUTOFVIDEOMEMORY;
176 }
177 adapter_adjust_memory(device->adapter, size);
178 }
179#endif
180
181 device_resource_add(device, resource);
182
183 return WINED3D_OK;
184}
185
186void resource_cleanup(struct wined3d_resource *resource)
187{
188#ifndef VBOX_WITH_WDDM
189 const struct wined3d *d3d = resource->device->wined3d;
190#endif
191 struct private_data *data;
192 struct list *e1, *e2;
193 HRESULT hr;
194
195 TRACE("Cleaning up resource %p.\n", resource);
196#ifndef VBOX_WITH_WDDM
197 if (resource->pool == WINED3D_POOL_DEFAULT && d3d->flags & WINED3D_VIDMEM_ACCOUNTING)
198 {
199 TRACE("Decrementing device memory pool by %u.\n", resource->size);
200 adapter_adjust_memory(resource->device->adapter, 0 - resource->size);
201 }
202#endif
203
204 LIST_FOR_EACH_SAFE(e1, e2, &resource->privateData)
205 {
206 data = LIST_ENTRY(e1, struct private_data, entry);
207 hr = wined3d_resource_free_private_data(resource, &data->tag);
208 if (FAILED(hr))
209 ERR("Failed to free private data when destroying resource %p, hr = %#x.\n", resource, hr);
210 }
211
212 HeapFree(GetProcessHeap(), 0, resource->heapMemory);
213 resource->allocatedMemory = 0;
214 resource->heapMemory = 0;
215
216 device_resource_released(resource->device, resource);
217}
218
219void resource_unload(struct wined3d_resource *resource)
220{
221 if (resource->map_count)
222 ERR("Resource %p is being unloaded while mapped.\n", resource);
223
224 context_resource_unloaded(resource->device,
225 resource, resource->type);
226}
227
228static struct private_data *resource_find_private_data(const struct wined3d_resource *resource, REFGUID tag)
229{
230 struct private_data *data;
231 struct list *entry;
232
233 TRACE("Searching for private data %s\n", debugstr_guid(tag));
234 LIST_FOR_EACH(entry, &resource->privateData)
235 {
236 data = LIST_ENTRY(entry, struct private_data, entry);
237 if (IsEqualGUID(&data->tag, tag)) {
238 TRACE("Found %p\n", data);
239 return data;
240 }
241 }
242 TRACE("Not found\n");
243 return NULL;
244}
245
246HRESULT CDECL wined3d_resource_set_private_data(struct wined3d_resource *resource, REFGUID guid,
247 const void *data, DWORD data_size, DWORD flags)
248{
249 struct private_data *d;
250
251 TRACE("resource %p, riid %s, data %p, data_size %u, flags %#x.\n",
252 resource, debugstr_guid(guid), data, data_size, flags);
253
254 wined3d_resource_free_private_data(resource, guid);
255
256 d = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*d));
257 if (!d) return E_OUTOFMEMORY;
258
259 d->tag = *guid;
260 d->flags = flags;
261
262 if (flags & WINED3DSPD_IUNKNOWN)
263 {
264 if (data_size != sizeof(IUnknown *))
265 {
266 WARN("IUnknown data with size %u, returning WINED3DERR_INVALIDCALL.\n", data_size);
267 HeapFree(GetProcessHeap(), 0, d);
268 return WINED3DERR_INVALIDCALL;
269 }
270 d->ptr.object = (IUnknown *)data;
271 d->size = sizeof(IUnknown *);
272 IUnknown_AddRef(d->ptr.object);
273 }
274 else
275 {
276 d->ptr.data = HeapAlloc(GetProcessHeap(), 0, data_size);
277 if (!d->ptr.data)
278 {
279 HeapFree(GetProcessHeap(), 0, d);
280 return E_OUTOFMEMORY;
281 }
282 d->size = data_size;
283 memcpy(d->ptr.data, data, data_size);
284 }
285 list_add_tail(&resource->privateData, &d->entry);
286
287 return WINED3D_OK;
288}
289
290HRESULT CDECL wined3d_resource_get_private_data(const struct wined3d_resource *resource, REFGUID guid,
291 void *data, DWORD *data_size)
292{
293 const struct private_data *d;
294
295 TRACE("resource %p, guid %s, data %p, data_size %p.\n",
296 resource, debugstr_guid(guid), data, data_size);
297
298 d = resource_find_private_data(resource, guid);
299 if (!d) return WINED3DERR_NOTFOUND;
300
301 if (*data_size < d->size)
302 {
303 *data_size = d->size;
304 return WINED3DERR_MOREDATA;
305 }
306
307 if (d->flags & WINED3DSPD_IUNKNOWN)
308 {
309 *(IUnknown **)data = d->ptr.object;
310 if (resource->device->wined3d->dxVersion != 7)
311 {
312 /* D3D8 and D3D9 addref the private data, DDraw does not. This
313 * can't be handled in ddraw because it doesn't know if the
314 * pointer returned is an IUnknown * or just a blob. */
315 IUnknown_AddRef(d->ptr.object);
316 }
317 }
318 else
319 {
320 memcpy(data, d->ptr.data, d->size);
321 }
322
323 return WINED3D_OK;
324}
325HRESULT CDECL wined3d_resource_free_private_data(struct wined3d_resource *resource, REFGUID guid)
326{
327 struct private_data *data;
328
329 TRACE("resource %p, guid %s.\n", resource, debugstr_guid(guid));
330
331 data = resource_find_private_data(resource, guid);
332 if (!data) return WINED3DERR_NOTFOUND;
333
334 if (data->flags & WINED3DSPD_IUNKNOWN)
335 {
336 if (data->ptr.object)
337 IUnknown_Release(data->ptr.object);
338 }
339 else
340 {
341 HeapFree(GetProcessHeap(), 0, data->ptr.data);
342 }
343 list_remove(&data->entry);
344
345 HeapFree(GetProcessHeap(), 0, data);
346
347 return WINED3D_OK;
348}
349
350DWORD resource_set_priority(struct wined3d_resource *resource, DWORD priority)
351{
352 DWORD prev = resource->priority;
353 resource->priority = priority;
354 TRACE("resource %p, new priority %u, returning old priority %u.\n", resource, priority, prev);
355 return prev;
356}
357
358DWORD resource_get_priority(const struct wined3d_resource *resource)
359{
360 TRACE("resource %p, returning %u.\n", resource, resource->priority);
361 return resource->priority;
362}
363
364void * CDECL wined3d_resource_get_parent(const struct wined3d_resource *resource)
365{
366 return resource->parent;
367}
368
369void CDECL wined3d_resource_get_desc(const struct wined3d_resource *resource, struct wined3d_resource_desc *desc)
370{
371 desc->resource_type = resource->type;
372 desc->format = resource->format->id;
373 desc->multisample_type = resource->multisample_type;
374 desc->multisample_quality = resource->multisample_quality;
375 desc->usage = resource->usage;
376 desc->pool = resource->pool;
377 desc->width = resource->width;
378 desc->height = resource->height;
379 desc->depth = resource->depth;
380 desc->size = resource->size;
381}
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