VirtualBox

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

Last change on this file since 53781 was 48345, checked in by vboxsync, 12 years ago

header fixes

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