VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c@ 32580

Last change on this file since 32580 was 30916, checked in by vboxsync, 14 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: 14.0 KB
Line 
1/*
2 * IDirect3DTexture9 implementation
3 *
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
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 * Sun 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, Sun 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 "d3d9_private.h"
34
35WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
36
37/* IDirect3DTexture9 IUnknown parts follow: */
38static HRESULT WINAPI IDirect3DTexture9Impl_QueryInterface(LPDIRECT3DTEXTURE9 iface, REFIID riid, LPVOID* ppobj) {
39 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
40
41 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
42
43 if (IsEqualGUID(riid, &IID_IUnknown)
44 || IsEqualGUID(riid, &IID_IDirect3DResource9)
45 || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
46 || IsEqualGUID(riid, &IID_IDirect3DTexture9)) {
47 IDirect3DTexture9_AddRef(iface);
48 *ppobj = This;
49 return S_OK;
50 }
51
52 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
53 *ppobj = NULL;
54 return E_NOINTERFACE;
55}
56
57static ULONG WINAPI IDirect3DTexture9Impl_AddRef(LPDIRECT3DTEXTURE9 iface) {
58 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
59 ULONG ref = InterlockedIncrement(&This->ref);
60
61 TRACE("%p increasing refcount to %u.\n", iface, ref);
62
63 if (ref == 1)
64 {
65 IDirect3DDevice9Ex_AddRef(This->parentDevice);
66 wined3d_mutex_lock();
67 IWineD3DTexture_AddRef(This->wineD3DTexture);
68 wined3d_mutex_unlock();
69 }
70
71 return ref;
72}
73
74static ULONG WINAPI IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface) {
75 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
76 ULONG ref = InterlockedDecrement(&This->ref);
77
78 TRACE("%p decreasing refcount to %u.\n", iface, ref);
79
80 if (ref == 0) {
81 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
82
83 wined3d_mutex_lock();
84 IWineD3DTexture_Release(This->wineD3DTexture);
85 wined3d_mutex_unlock();
86
87 /* Release the device last, as it may cause the device to be destroyed. */
88 IDirect3DDevice9Ex_Release(parentDevice);
89 }
90 return ref;
91}
92
93/* IDirect3DTexture9 IDirect3DResource9 Interface follow: */
94static HRESULT WINAPI IDirect3DTexture9Impl_GetDevice(IDirect3DTexture9 *iface, IDirect3DDevice9 **device)
95{
96 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
97
98 TRACE("iface %p, device %p.\n", iface, device);
99
100 *device = (IDirect3DDevice9 *)This->parentDevice;
101 IDirect3DDevice9_AddRef(*device);
102
103 TRACE("Returning device %p.\n", *device);
104
105 return D3D_OK;
106}
107
108static HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
109 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
110 HRESULT hr;
111
112 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
113 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
114
115 wined3d_mutex_lock();
116 hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
117 wined3d_mutex_unlock();
118
119 return hr;
120}
121
122static HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
123 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
124 HRESULT hr;
125
126 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
127 iface, debugstr_guid(refguid), pData, pSizeOfData);
128
129 wined3d_mutex_lock();
130 hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
131 wined3d_mutex_unlock();
132
133 return hr;
134}
135
136static HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(LPDIRECT3DTEXTURE9 iface, REFGUID refguid) {
137 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
138 HRESULT hr;
139
140 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
141
142 wined3d_mutex_lock();
143 hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
144 wined3d_mutex_unlock();
145
146 return hr;
147}
148
149static DWORD WINAPI IDirect3DTexture9Impl_SetPriority(LPDIRECT3DTEXTURE9 iface, DWORD PriorityNew) {
150 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
151 DWORD ret;
152
153 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
154
155 wined3d_mutex_lock();
156 ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
157 wined3d_mutex_unlock();
158
159 return ret;
160}
161
162static DWORD WINAPI IDirect3DTexture9Impl_GetPriority(LPDIRECT3DTEXTURE9 iface) {
163 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
164 DWORD ret;
165
166 TRACE("iface %p.\n", iface);
167
168 wined3d_mutex_lock();
169 ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
170 wined3d_mutex_unlock();
171
172 return ret;
173}
174
175static void WINAPI IDirect3DTexture9Impl_PreLoad(LPDIRECT3DTEXTURE9 iface) {
176 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
177
178 TRACE("iface %p.\n", iface);
179
180 wined3d_mutex_lock();
181 IWineD3DTexture_PreLoad(This->wineD3DTexture);
182 wined3d_mutex_unlock();
183}
184
185static D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(LPDIRECT3DTEXTURE9 iface) {
186 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
187 HRESULT ret;
188
189 TRACE("iface %p.\n", iface);
190
191 wined3d_mutex_lock();
192 ret = IWineD3DTexture_GetType(This->wineD3DTexture);
193 wined3d_mutex_unlock();
194
195 return ret;
196}
197
198/* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
199static DWORD WINAPI IDirect3DTexture9Impl_SetLOD(LPDIRECT3DTEXTURE9 iface, DWORD LODNew) {
200 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
201 DWORD ret;
202
203 TRACE("iface %p, lod %u.\n", iface, LODNew);
204
205 wined3d_mutex_lock();
206 ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
207 wined3d_mutex_unlock();
208
209 return ret;
210}
211
212static DWORD WINAPI IDirect3DTexture9Impl_GetLOD(LPDIRECT3DTEXTURE9 iface) {
213 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
214 DWORD ret;
215
216 TRACE("iface %p.\n", iface);
217
218 wined3d_mutex_lock();
219 ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
220 wined3d_mutex_unlock();
221
222 return ret;
223}
224
225static DWORD WINAPI IDirect3DTexture9Impl_GetLevelCount(LPDIRECT3DTEXTURE9 iface) {
226 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
227 DWORD ret;
228
229 TRACE("iface %p.\n", iface);
230
231 wined3d_mutex_lock();
232 ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
233 wined3d_mutex_unlock();
234
235 return ret;
236}
237
238static HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface, D3DTEXTUREFILTERTYPE FilterType) {
239 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
240 HRESULT hr;
241
242 TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
243
244 wined3d_mutex_lock();
245 hr = IWineD3DTexture_SetAutoGenFilterType(This->wineD3DTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
246 wined3d_mutex_unlock();
247
248 return hr;
249}
250
251static D3DTEXTUREFILTERTYPE WINAPI IDirect3DTexture9Impl_GetAutoGenFilterType(LPDIRECT3DTEXTURE9 iface) {
252 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
253 D3DTEXTUREFILTERTYPE ret;
254
255 TRACE("iface %p.\n", iface);
256
257 wined3d_mutex_lock();
258 ret = (D3DTEXTUREFILTERTYPE) IWineD3DTexture_GetAutoGenFilterType(This->wineD3DTexture);
259 wined3d_mutex_unlock();
260
261 return ret;
262}
263
264static void WINAPI IDirect3DTexture9Impl_GenerateMipSubLevels(LPDIRECT3DTEXTURE9 iface) {
265 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
266
267 TRACE("iface %p.\n", iface);
268
269 wined3d_mutex_lock();
270 IWineD3DTexture_GenerateMipSubLevels(This->wineD3DTexture);
271 wined3d_mutex_unlock();
272}
273
274/* IDirect3DTexture9 Interface follow: */
275static HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
276 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
277 WINED3DSURFACE_DESC wined3ddesc;
278 HRESULT hr;
279
280 TRACE("iface %p, level %u, desc %p.\n", iface, Level, pDesc);
281
282 wined3d_mutex_lock();
283 hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
284 wined3d_mutex_unlock();
285
286 if (SUCCEEDED(hr))
287 {
288 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
289 pDesc->Type = wined3ddesc.resource_type;
290 pDesc->Usage = wined3ddesc.usage;
291 pDesc->Pool = wined3ddesc.pool;
292 pDesc->MultiSampleType = wined3ddesc.multisample_type;
293 pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
294 pDesc->Width = wined3ddesc.width;
295 pDesc->Height = wined3ddesc.height;
296 }
297
298 return hr;
299}
300
301static HRESULT WINAPI IDirect3DTexture9Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE9 iface, UINT Level, IDirect3DSurface9** ppSurfaceLevel) {
302 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
303 HRESULT hrc = D3D_OK;
304 IWineD3DSurface *mySurface = NULL;
305
306 TRACE("iface %p, level %u, surface %p.\n", iface, Level, ppSurfaceLevel);
307
308 wined3d_mutex_lock();
309 hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
310 if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
311 IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppSurfaceLevel);
312 IWineD3DSurface_Release(mySurface);
313 }
314 wined3d_mutex_unlock();
315
316 return hrc;
317}
318
319static HRESULT WINAPI IDirect3DTexture9Impl_LockRect(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
320 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
321 HRESULT hr;
322
323 TRACE("iface %p, level %u, locked_rect %p, rect %p, flags %#x.\n",
324 iface, Level, pLockedRect, pRect, Flags);
325
326 wined3d_mutex_lock();
327 hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
328 wined3d_mutex_unlock();
329
330 return hr;
331}
332
333static HRESULT WINAPI IDirect3DTexture9Impl_UnlockRect(LPDIRECT3DTEXTURE9 iface, UINT Level) {
334 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
335 HRESULT hr;
336
337 TRACE("iface %p, level %u.\n", iface, Level);
338
339 wined3d_mutex_lock();
340 hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
341 wined3d_mutex_unlock();
342
343 return hr;
344}
345
346static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(LPDIRECT3DTEXTURE9 iface, CONST RECT* pDirtyRect) {
347 IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
348 HRESULT hr;
349
350 TRACE("iface %p, dirty_rect %p.\n", iface, pDirtyRect);
351
352 wined3d_mutex_lock();
353 hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
354 wined3d_mutex_unlock();
355
356 return hr;
357}
358
359static const IDirect3DTexture9Vtbl Direct3DTexture9_Vtbl =
360{
361 /* IUnknown */
362 IDirect3DTexture9Impl_QueryInterface,
363 IDirect3DTexture9Impl_AddRef,
364 IDirect3DTexture9Impl_Release,
365 /* IDirect3DResource9 */
366 IDirect3DTexture9Impl_GetDevice,
367 IDirect3DTexture9Impl_SetPrivateData,
368 IDirect3DTexture9Impl_GetPrivateData,
369 IDirect3DTexture9Impl_FreePrivateData,
370 IDirect3DTexture9Impl_SetPriority,
371 IDirect3DTexture9Impl_GetPriority,
372 IDirect3DTexture9Impl_PreLoad,
373 IDirect3DTexture9Impl_GetType,
374 /* IDirect3dBaseTexture9 */
375 IDirect3DTexture9Impl_SetLOD,
376 IDirect3DTexture9Impl_GetLOD,
377 IDirect3DTexture9Impl_GetLevelCount,
378 IDirect3DTexture9Impl_SetAutoGenFilterType,
379 IDirect3DTexture9Impl_GetAutoGenFilterType,
380 IDirect3DTexture9Impl_GenerateMipSubLevels,
381 /* IDirect3DTexture9 */
382 IDirect3DTexture9Impl_GetLevelDesc,
383 IDirect3DTexture9Impl_GetSurfaceLevel,
384 IDirect3DTexture9Impl_LockRect,
385 IDirect3DTexture9Impl_UnlockRect,
386 IDirect3DTexture9Impl_AddDirtyRect
387};
388
389static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
390{
391 HeapFree(GetProcessHeap(), 0, parent);
392}
393
394static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
395{
396 d3d9_texture_wined3d_object_destroyed,
397};
398
399HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
400 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool
401#ifdef VBOXWDDM
402 , HANDLE *shared_handle
403 , void *pvClientMem
404#endif
405 )
406{
407 HRESULT hr;
408
409 texture->lpVtbl = &Direct3DTexture9_Vtbl;
410 texture->ref = 1;
411
412 wined3d_mutex_lock();
413#ifdef VBOXWDDM
414 hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
415 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
416 &texture->wineD3DTexture, (IUnknown *)texture, &d3d9_texture_wined3d_parent_ops
417 , shared_handle
418 , pvClientMem);
419#else
420 hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
421 usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
422 &texture->wineD3DTexture, (IUnknown *)texture, &d3d9_texture_wined3d_parent_ops);
423#endif
424
425 wined3d_mutex_unlock();
426 if (FAILED(hr))
427 {
428 WARN("Failed to create wined3d texture, hr %#x.\n", hr);
429 return hr;
430 }
431
432 texture->parentDevice = (IDirect3DDevice9Ex *)device;
433 IDirect3DDevice9Ex_AddRef(texture->parentDevice);
434
435 return D3D_OK;
436}
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