VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c@ 30585

Last change on this file since 30585 was 25949, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.36 and disable unnecessary fbo state poll

  • Property svn:eol-style set to native
File size: 13.5 KB
Line 
1/*
2 * IDirect3DSurface9 implementation
3 *
4 * Copyright 2002-2005 Jason Edmeades
5 * Raphael Junqueira
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 * Sun 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, Sun 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 "d3d9_private.h"
33
34WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
35
36/* IDirect3DSurface9 IUnknown parts follow: */
37static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface, REFIID riid, LPVOID* ppobj) {
38 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
39
40 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
41
42 if (IsEqualGUID(riid, &IID_IUnknown)
43 || IsEqualGUID(riid, &IID_IDirect3DResource9)
44 || IsEqualGUID(riid, &IID_IDirect3DSurface9)) {
45 IDirect3DSurface9_AddRef(iface);
46 *ppobj = This;
47 return S_OK;
48 }
49
50 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
51 *ppobj = NULL;
52 return E_NOINTERFACE;
53}
54
55static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
56 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
57
58 TRACE("iface %p.\n", iface);
59
60 if (This->forwardReference) {
61 /* Forward refcounting */
62 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
63 return IUnknown_AddRef(This->forwardReference);
64 } else {
65 /* No container, handle our own refcounting */
66 ULONG ref = InterlockedIncrement(&This->ref);
67
68 TRACE("%p increasing refcount to %u.\n", iface, ref);
69
70 if (ref == 1)
71 {
72 if (This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
73 wined3d_mutex_lock();
74 IWineD3DSurface_AddRef(This->wineD3DSurface);
75 wined3d_mutex_unlock();
76 }
77
78 return ref;
79 }
80
81}
82
83static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
84 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
85
86 TRACE("iface %p.\n", iface);
87
88 if (This->forwardReference) {
89 /* Forward to the containerParent */
90 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
91 return IUnknown_Release(This->forwardReference);
92 } else {
93 /* No container, handle our own refcounting */
94 ULONG ref = InterlockedDecrement(&This->ref);
95
96 TRACE("%p decreasing refcount to %u.\n", iface, ref);
97
98 if (ref == 0) {
99 IDirect3DDevice9Ex *parentDevice = This->parentDevice;
100
101 wined3d_mutex_lock();
102 IWineD3DSurface_Release(This->wineD3DSurface);
103 wined3d_mutex_unlock();
104
105 /* Release the device last, as it may cause the device to be destroyed. */
106 if (parentDevice) IDirect3DDevice9Ex_Release(parentDevice);
107 }
108
109 return ref;
110 }
111}
112
113/* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
114static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, IDirect3DDevice9 **device)
115{
116 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
117
118 TRACE("iface %p, device %p.\n", iface, device);
119
120 if (This->forwardReference)
121 {
122 IDirect3DResource9 *resource;
123 HRESULT hr;
124
125 hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource);
126 if (SUCCEEDED(hr))
127 {
128 hr = IDirect3DResource9_GetDevice(resource, device);
129 IDirect3DResource9_Release(resource);
130
131 TRACE("Returning device %p.\n", *device);
132 }
133
134 return hr;
135 }
136
137 *device = (IDirect3DDevice9 *)This->parentDevice;
138 IDirect3DDevice9_AddRef(*device);
139
140 TRACE("Returning device %p.\n", *device);
141
142 return D3D_OK;
143}
144
145static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
146 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
147 HRESULT hr;
148
149 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
150 iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
151
152 wined3d_mutex_lock();
153 hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
154 wined3d_mutex_unlock();
155
156 return hr;
157}
158
159static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
160 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
161 HRESULT hr;
162
163 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
164 iface, debugstr_guid(refguid), pData, pSizeOfData);
165
166 wined3d_mutex_lock();
167 hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
168 wined3d_mutex_unlock();
169
170 return hr;
171}
172
173static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
174 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
175 HRESULT hr;
176
177 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
178
179 wined3d_mutex_lock();
180 hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
181 wined3d_mutex_unlock();
182
183 return hr;
184}
185
186static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
187 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
188 HRESULT hr;
189
190 TRACE("iface %p, priority %u.\n", iface, PriorityNew);
191
192 wined3d_mutex_lock();
193 hr = IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
194 wined3d_mutex_unlock();
195
196 return hr;
197}
198
199static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
200 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
201 HRESULT hr;
202
203 TRACE("iface %p.\n", iface);
204
205 wined3d_mutex_lock();
206 hr = IWineD3DSurface_GetPriority(This->wineD3DSurface);
207 wined3d_mutex_unlock();
208
209 return hr;
210}
211
212static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
213 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
214
215 TRACE("iface %p.\n", iface);
216
217 wined3d_mutex_lock();
218 IWineD3DSurface_PreLoad(This->wineD3DSurface);
219 wined3d_mutex_unlock();
220}
221
222static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
223 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
224 D3DRESOURCETYPE ret;
225
226 TRACE("iface %p.\n", iface);
227
228 wined3d_mutex_lock();
229 ret = IWineD3DSurface_GetType(This->wineD3DSurface);
230 wined3d_mutex_unlock();
231
232 return ret;
233}
234
235/* IDirect3DSurface9 Interface follow: */
236static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
237 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
238 HRESULT res;
239
240 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
241
242 if (!This->container) return E_NOINTERFACE;
243
244 if (!ppContainer) {
245 ERR("Called without a valid ppContainer\n");
246 }
247
248 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
249
250 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
251
252 return res;
253}
254
255static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
256 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
257 WINED3DSURFACE_DESC wined3ddesc;
258 HRESULT hr;
259
260 TRACE("iface %p, desc %p.\n", iface, pDesc);
261
262 wined3d_mutex_lock();
263 hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
264 wined3d_mutex_unlock();
265
266 if (SUCCEEDED(hr))
267 {
268 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
269 pDesc->Type = wined3ddesc.resource_type;
270 pDesc->Usage = wined3ddesc.usage;
271 pDesc->Pool = wined3ddesc.pool;
272 pDesc->MultiSampleType = wined3ddesc.multisample_type;
273 pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
274 pDesc->Width = wined3ddesc.width;
275 pDesc->Height = wined3ddesc.height;
276 }
277
278 return hr;
279}
280
281static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
282 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
283 HRESULT hr;
284
285 TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags);
286
287 wined3d_mutex_lock();
288 hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
289 wined3d_mutex_unlock();
290
291 return hr;
292}
293
294static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
295 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
296 HRESULT hr;
297
298 TRACE("iface %p.\n", iface);
299
300 wined3d_mutex_lock();
301 hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
302 wined3d_mutex_unlock();
303
304 switch(hr)
305 {
306 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
307 default: return hr;
308 }
309}
310
311static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
312 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
313 HRESULT hr;
314
315 TRACE("iface %p, hdc %p.\n", iface, phdc);
316
317 if(!This->getdc_supported)
318 {
319 WARN("Surface does not support GetDC, returning D3DERR_INVALIDCALL\n");
320 /* Don't touch the DC */
321 return D3DERR_INVALIDCALL;
322 }
323
324 wined3d_mutex_lock();
325 hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
326 wined3d_mutex_unlock();
327
328 return hr;
329}
330
331static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
332 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
333 HRESULT hr;
334
335 TRACE("iface %p, hdc %p.\n", iface, hdc);
336
337 wined3d_mutex_lock();
338 hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
339 wined3d_mutex_unlock();
340
341 switch(hr) {
342 case WINEDDERR_NODC: return WINED3DERR_INVALIDCALL;
343 default: return hr;
344 }
345}
346
347static const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
348{
349 /* IUnknown */
350 IDirect3DSurface9Impl_QueryInterface,
351 IDirect3DSurface9Impl_AddRef,
352 IDirect3DSurface9Impl_Release,
353 /* IDirect3DResource9 */
354 IDirect3DSurface9Impl_GetDevice,
355 IDirect3DSurface9Impl_SetPrivateData,
356 IDirect3DSurface9Impl_GetPrivateData,
357 IDirect3DSurface9Impl_FreePrivateData,
358 IDirect3DSurface9Impl_SetPriority,
359 IDirect3DSurface9Impl_GetPriority,
360 IDirect3DSurface9Impl_PreLoad,
361 IDirect3DSurface9Impl_GetType,
362 /* IDirect3DSurface9 */
363 IDirect3DSurface9Impl_GetContainer,
364 IDirect3DSurface9Impl_GetDesc,
365 IDirect3DSurface9Impl_LockRect,
366 IDirect3DSurface9Impl_UnlockRect,
367 IDirect3DSurface9Impl_GetDC,
368 IDirect3DSurface9Impl_ReleaseDC
369};
370
371static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
372{
373 HeapFree(GetProcessHeap(), 0, parent);
374}
375
376static const struct wined3d_parent_ops d3d9_surface_wined3d_parent_ops =
377{
378 surface_wined3d_object_destroyed,
379};
380
381HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
382 UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
383 DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
384{
385 HRESULT hr;
386
387 surface->lpVtbl = &Direct3DSurface9_Vtbl;
388 surface->ref = 1;
389
390 switch (format)
391 {
392 case D3DFMT_A8R8G8B8:
393 case D3DFMT_X8R8G8B8:
394 case D3DFMT_R5G6B5:
395 case D3DFMT_X1R5G5B5:
396 case D3DFMT_A1R5G5B5:
397 case D3DFMT_R8G8B8:
398 surface->getdc_supported = TRUE;
399 break;
400
401 default:
402 surface->getdc_supported = FALSE;
403 break;
404 }
405
406 /* FIXME: Check MAX bounds of MultisampleQuality. */
407 if (multisample_quality > 0)
408 {
409 FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
410 multisample_quality = 0;
411 }
412
413 wined3d_mutex_lock();
414 hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
415 lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
416 multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface,
417 &d3d9_surface_wined3d_parent_ops);
418 wined3d_mutex_unlock();
419 if (FAILED(hr))
420 {
421 WARN("Failed to create wined3d surface, hr %#x.\n", hr);
422 return hr;
423 }
424
425 surface->parentDevice = (IDirect3DDevice9Ex *)device;
426 IDirect3DDevice9Ex_AddRef(surface->parentDevice);
427
428 return D3D_OK;
429}
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