VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/volume.c@ 46757

Last change on this file since 46757 was 46521, checked in by vboxsync, 12 years ago

wine/new: export

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 KB
Line 
1/*
2 * Copyright 2002-2005 Jason Edmeades
3 * Copyright 2002-2005 Raphael Junqueira
4 * Copyright 2005 Oliver Stieber
5 * Copyright 2009-2011 Henri Verbeet for CodeWeavers
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include "config.h"
23#include "wine/port.h"
24#include "wined3d_private.h"
25
26#ifdef VBOX_WITH_WDDM
27# include "../../common/VBoxVideoTools.h"
28#endif
29
30WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
31
32/* Context activation is done by the caller. */
33static void volume_bind_and_dirtify(const struct wined3d_volume *volume, struct wined3d_context *context)
34{
35 struct wined3d_texture *container = volume->container;
36 DWORD active_sampler;
37
38 /* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
39 * Read the unit back instead of switching to 0, this avoids messing around with the state manager's
40 * gl states. The current texture unit should always be a valid one.
41 *
42 * To be more specific, this is tricky because we can implicitly be called
43 * from sampler() in state.c. This means we can't touch anything other than
44 * whatever happens to be the currently active texture, or we would risk
45 * marking already applied sampler states dirty again. */
46 active_sampler = volume->resource.device->rev_tex_unit_map[context->active_texture];
47
48 if (active_sampler != WINED3D_UNMAPPED_STAGE)
49 device_invalidate_state(volume->resource.device, STATE_SAMPLER(active_sampler));
50
51 container->texture_ops->texture_bind(container, context, FALSE);
52}
53
54void volume_add_dirty_box(struct wined3d_volume *volume, const struct wined3d_box *dirty_box)
55{
56 volume->dirty = TRUE;
57 if (dirty_box)
58 {
59 volume->lockedBox.left = min(volume->lockedBox.left, dirty_box->left);
60 volume->lockedBox.top = min(volume->lockedBox.top, dirty_box->top);
61 volume->lockedBox.front = min(volume->lockedBox.front, dirty_box->front);
62 volume->lockedBox.right = max(volume->lockedBox.right, dirty_box->right);
63 volume->lockedBox.bottom = max(volume->lockedBox.bottom, dirty_box->bottom);
64 volume->lockedBox.back = max(volume->lockedBox.back, dirty_box->back);
65 }
66 else
67 {
68 volume->lockedBox.left = 0;
69 volume->lockedBox.top = 0;
70 volume->lockedBox.front = 0;
71 volume->lockedBox.right = volume->resource.width;
72 volume->lockedBox.bottom = volume->resource.height;
73 volume->lockedBox.back = volume->resource.depth;
74 }
75}
76
77void volume_set_container(struct wined3d_volume *volume, struct wined3d_texture *container)
78{
79 TRACE("volume %p, container %p.\n", volume, container);
80
81 volume->container = container;
82}
83
84/* Context activation is done by the caller. */
85void volume_load(const struct wined3d_volume *volume, struct wined3d_context *context, UINT level, BOOL srgb_mode)
86{
87 const struct wined3d_gl_info *gl_info = context->gl_info;
88 const struct wined3d_format *format = volume->resource.format;
89
90 TRACE("volume %p, context %p, level %u, srgb %#x, format %s (%#x).\n",
91 volume, context, level, srgb_mode, debug_d3dformat(format->id), format->id);
92
93 volume_bind_and_dirtify(volume, context);
94
95 GL_EXTCALL(glTexImage3DEXT(GL_TEXTURE_3D, level, format->glInternal,
96 volume->resource.width, volume->resource.height, volume->resource.depth,
97 0, format->glFormat, format->glType, volume->resource.allocatedMemory));
98 checkGLcall("glTexImage3D");
99
100 /* When adding code releasing volume->resource.allocatedMemory to save
101 * data keep in mind that GL_UNPACK_CLIENT_STORAGE_APPLE is enabled by
102 * default if supported(GL_APPLE_client_storage). Thus do not release
103 * volume->resource.allocatedMemory if GL_APPLE_client_storage is
104 * supported. */
105}
106
107/* Do not call while under the GL lock. */
108static void volume_unload(struct wined3d_resource *resource)
109{
110 TRACE("texture %p.\n", resource);
111
112 /* The whole content is shadowed on This->resource.allocatedMemory, and
113 * the texture name is managed by the VolumeTexture container. */
114
115 resource_unload(resource);
116}
117
118ULONG CDECL wined3d_volume_incref(struct wined3d_volume *volume)
119{
120 ULONG refcount;
121
122 if (volume->container)
123 {
124 TRACE("Forwarding to container %p.\n", volume->container);
125 return wined3d_texture_incref(volume->container);
126 }
127
128 refcount = InterlockedIncrement(&volume->resource.ref);
129
130 TRACE("%p increasing refcount to %u.\n", volume, refcount);
131
132 return refcount;
133}
134
135/* Do not call while under the GL lock. */
136ULONG CDECL wined3d_volume_decref(struct wined3d_volume *volume)
137{
138 ULONG refcount;
139
140 if (volume->container)
141 {
142 TRACE("Forwarding to container %p.\n", volume->container);
143 return wined3d_texture_decref(volume->container);
144 }
145
146 refcount = InterlockedDecrement(&volume->resource.ref);
147
148 TRACE("%p decreasing refcount to %u.\n", volume, refcount);
149
150 if (!refcount)
151 {
152 resource_cleanup(&volume->resource);
153 volume->resource.parent_ops->wined3d_object_destroyed(volume->resource.parent);
154 HeapFree(GetProcessHeap(), 0, volume);
155 }
156
157 return refcount;
158}
159
160void * CDECL wined3d_volume_get_parent(const struct wined3d_volume *volume)
161{
162 TRACE("volume %p.\n", volume);
163
164 return volume->resource.parent;
165}
166
167DWORD CDECL wined3d_volume_set_priority(struct wined3d_volume *volume, DWORD priority)
168{
169 return resource_set_priority(&volume->resource, priority);
170}
171
172DWORD CDECL wined3d_volume_get_priority(const struct wined3d_volume *volume)
173{
174 return resource_get_priority(&volume->resource);
175}
176
177/* Do not call while under the GL lock. */
178void CDECL wined3d_volume_preload(struct wined3d_volume *volume)
179{
180 FIXME("volume %p stub!\n", volume);
181}
182
183struct wined3d_resource * CDECL wined3d_volume_get_resource(struct wined3d_volume *volume)
184{
185 TRACE("volume %p.\n", volume);
186
187 return &volume->resource;
188}
189
190HRESULT CDECL wined3d_volume_map(struct wined3d_volume *volume,
191 struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags)
192{
193 TRACE("volume %p, map_desc %p, box %p, flags %#x.\n",
194 volume, map_desc, box, flags);
195
196 if (!volume->resource.allocatedMemory)
197 volume->resource.allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, volume->resource.size);
198
199 TRACE("allocatedMemory %p.\n", volume->resource.allocatedMemory);
200
201 map_desc->row_pitch = volume->resource.format->byte_count * volume->resource.width; /* Bytes / row */
202 map_desc->slice_pitch = volume->resource.format->byte_count
203 * volume->resource.width * volume->resource.height; /* Bytes / slice */
204 if (!box)
205 {
206 TRACE("No box supplied - all is ok\n");
207 map_desc->data = volume->resource.allocatedMemory;
208 volume->lockedBox.left = 0;
209 volume->lockedBox.top = 0;
210 volume->lockedBox.front = 0;
211 volume->lockedBox.right = volume->resource.width;
212 volume->lockedBox.bottom = volume->resource.height;
213 volume->lockedBox.back = volume->resource.depth;
214 }
215 else
216 {
217#ifdef VBOX_WITH_WDDM
218 if (box->right <= box->left
219 || box->right > volume->resource.width
220 || box->bottom <= box->top
221 || box->bottom > volume->resource.height
222 || box->back <= box->front
223 || box->back > volume->resource.depth
224 )
225 {
226 ERR("invalid dimensions!");
227 return WINED3DERR_INVALIDCALL;
228 }
229#endif
230 TRACE("Lock Box (%p) = l %u, t %u, r %u, b %u, fr %u, ba %u\n",
231 box, box->left, box->top, box->right, box->bottom, box->front, box->back);
232 map_desc->data = volume->resource.allocatedMemory
233 + (map_desc->slice_pitch * box->front) /* FIXME: is front < back or vica versa? */
234 + (map_desc->row_pitch * box->top)
235 + (box->left * volume->resource.format->byte_count);
236 volume->lockedBox.left = box->left;
237 volume->lockedBox.top = box->top;
238 volume->lockedBox.front = box->front;
239 volume->lockedBox.right = box->right;
240 volume->lockedBox.bottom = box->bottom;
241 volume->lockedBox.back = box->back;
242 }
243
244 if (!(flags & (WINED3D_MAP_NO_DIRTY_UPDATE | WINED3D_MAP_READONLY)))
245 {
246 volume_add_dirty_box(volume, &volume->lockedBox);
247 wined3d_texture_set_dirty(volume->container, TRUE);
248 }
249
250 volume->locked = TRUE;
251
252 TRACE("Returning memory %p, row pitch %d, slice pitch %d.\n",
253 map_desc->data, map_desc->row_pitch, map_desc->slice_pitch);
254
255 return WINED3D_OK;
256}
257
258struct wined3d_volume * CDECL wined3d_volume_from_resource(struct wined3d_resource *resource)
259{
260 return volume_from_resource(resource);
261}
262
263HRESULT CDECL wined3d_volume_unmap(struct wined3d_volume *volume)
264{
265 TRACE("volume %p.\n", volume);
266
267 if (!volume->locked)
268 {
269 WARN("Trying to unlock unlocked volume %p.\n", volume);
270 return WINED3DERR_INVALIDCALL;
271 }
272
273 volume->locked = FALSE;
274 memset(&volume->lockedBox, 0, sizeof(volume->lockedBox));
275
276 return WINED3D_OK;
277}
278
279static const struct wined3d_resource_ops volume_resource_ops =
280{
281 volume_unload,
282};
283
284static HRESULT volume_init(struct wined3d_volume *volume, struct wined3d_device *device, UINT width,
285 UINT height, UINT depth, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool,
286 void *parent, const struct wined3d_parent_ops *parent_ops
287#ifdef VBOX_WITH_WDDM
288 , HANDLE *shared_handle
289 , void *pvClientMem
290#endif
291 )
292{
293 const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
294 const struct wined3d_format *format = wined3d_get_format(gl_info, format_id);
295 HRESULT hr;
296
297 if (!gl_info->supported[EXT_TEXTURE3D])
298 {
299 WARN("Volume cannot be created - no volume texture support.\n");
300 return WINED3DERR_INVALIDCALL;
301 }
302
303 hr = resource_init(&volume->resource, device, WINED3D_RTYPE_VOLUME, format,
304 WINED3D_MULTISAMPLE_NONE, 0, usage, pool, width, height, depth,
305 width * height * depth * format->byte_count, parent, parent_ops,
306 &volume_resource_ops
307#ifdef VBOX_WITH_WDDM
308 , shared_handle, pvClientMem
309#endif
310 );
311 if (FAILED(hr))
312 {
313 WARN("Failed to initialize resource, returning %#x.\n", hr);
314 return hr;
315 }
316
317 volume->lockable = TRUE;
318 volume->locked = FALSE;
319 memset(&volume->lockedBox, 0, sizeof(volume->lockedBox));
320 volume->dirty = TRUE;
321
322 volume_add_dirty_box(volume, NULL);
323
324 return WINED3D_OK;
325}
326
327HRESULT CDECL wined3d_volume_create(struct wined3d_device *device, UINT width, UINT height,
328 UINT depth, DWORD usage, enum wined3d_format_id format_id, enum wined3d_pool pool, void *parent,
329 const struct wined3d_parent_ops *parent_ops, struct wined3d_volume **volume
330#ifdef VBOX_WITH_WDDM
331 , HANDLE *shared_handle
332 , void *pvClientMem
333#endif
334 )
335{
336 struct wined3d_volume *object;
337 HRESULT hr;
338
339 TRACE("device %p, width %u, height %u, depth %u, usage %#x, format %s, pool %s\n",
340 device, width, height, depth, usage, debug_d3dformat(format_id), debug_d3dpool(pool));
341 TRACE("parent %p, parent_ops %p, volume %p.\n", parent, parent_ops, volume);
342
343 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
344 if (!object)
345 {
346 *volume = NULL;
347 return WINED3DERR_OUTOFVIDEOMEMORY;
348 }
349
350 hr = volume_init(object, device, width, height, depth, usage, format_id, pool, parent, parent_ops
351#ifdef VBOX_WITH_WDDM
352 , shared_handle
353 , pvClientMem
354#endif
355 );
356 if (FAILED(hr))
357 {
358 WARN("Failed to initialize volume, returning %#x.\n", hr);
359 HeapFree(GetProcessHeap(), 0, object);
360 return hr;
361 }
362
363 TRACE("Created volume %p.\n", object);
364 *volume = object;
365
366 return WINED3D_OK;
367}
368
369#ifdef VBOX_WITH_WDDM
370HRESULT CDECL wined3d_device_blt_vol(struct wined3d_device *device, struct wined3d_volume *src, struct wined3d_volume *dst,
371 const struct wined3d_box *pSrcBoxArg,
372 const VBOXPOINT3D *pDstPoin3D)
373{
374 struct wined3d_map_desc src_desc, dst_desc;
375 HRESULT hr;
376 struct wined3d_box DstBox, SrcBox;
377 const struct wined3d_box *pDstBox;
378 const struct wined3d_box *pSrcBox;
379 int dstW, dstH, dstD, srcW, srcH, srcD;
380 int j, k;
381 uint8_t * pDstBits;
382 uint8_t * pSrcBits;
383
384
385 TRACE("device %p, src_volume %p, dst_volume %p.\n",
386 device, src, dst);
387
388 pSrcBox = pSrcBoxArg;
389 if (!pSrcBox)
390 {
391 SrcBox.left = 0;
392 SrcBox.top = 0;
393 SrcBox.front = 0;
394 SrcBox.right = src->resource.width;
395 SrcBox.bottom = src->resource.height;
396 SrcBox.back = src->resource.depth;
397 pSrcBox = &SrcBox;
398 }
399
400 if (!pDstPoin3D)
401 pDstBox = pSrcBox;
402 else
403 {
404 vboxWddmBoxTranslated((VBOXBOX3D*)&DstBox, (const VBOXBOX3D *)pSrcBox, pDstPoin3D->x, pDstPoin3D->y, pDstPoin3D->z);
405 pDstBox = &DstBox;
406 }
407
408 dstW = pDstBox->right - pDstBox->left;
409 dstH = pDstBox->bottom - pDstBox->top;
410 dstD = pDstBox->back - pDstBox->front;
411
412 srcW = pSrcBox->right - pSrcBox->left;
413 srcH = pSrcBox->bottom - pSrcBox->top;
414 srcD = pSrcBox->back - pSrcBox->front;
415
416 if (srcW != dstW || srcH != dstH || srcD != dstD)
417 {
418 ERR("dimensions do not match, stretching not supported for volumes!");
419 return WINED3DERR_INVALIDCALL;
420 }
421
422 /* TODO: Implement direct loading into the gl volume instead of using memcpy and
423 * dirtification to improve loading performance.
424 */
425 hr = wined3d_volume_map(src, &src_desc, pSrcBox, WINED3D_MAP_READONLY);
426 if(FAILED(hr))
427 {
428 ERR("wined3d_volume_map src failed");
429 return hr;
430 }
431
432 hr = wined3d_volume_map(dst, &dst_desc, pDstBox, WINED3D_MAP_DISCARD);
433 if(FAILED(hr))
434 {
435 ERR("wined3d_volume_map dst failed");
436 wined3d_volume_unmap(src);
437 return hr;
438 }
439
440 pDstBits = dst_desc.data;
441 pSrcBits = src_desc.data;
442 for (k = 0; k < srcD; ++k)
443 {
444 uint8_t * pRowDstBits = pDstBits;
445 uint8_t * pRowSrcBits = pSrcBits;
446
447 for (j = 0; j < srcH; ++j)
448 {
449 memcpy(pRowDstBits, pRowSrcBits, srcW * dst->resource.format->byte_count);
450 pRowDstBits += dst_desc.row_pitch;
451 pRowSrcBits += src_desc.row_pitch;
452 }
453 pDstBits += dst_desc.slice_pitch;
454 pSrcBits += src_desc.slice_pitch;
455 }
456
457 hr = wined3d_volume_unmap(dst);
458 if(FAILED(hr)) {
459 wined3d_volume_unmap(src);
460 } else {
461 hr = wined3d_volume_unmap(src);
462 }
463 return hr;
464}
465#endif
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