VirtualBox

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

Last change on this file since 19678 was 19678, checked in by vboxsync, 16 years ago

opengl: update wine to 1.1.21, add d3d9.dll to build list

  • Property svn:eol-style set to native
File size: 11.3 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 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IDirect3DResource9)
42 || IsEqualGUID(riid, &IID_IDirect3DSurface9)) {
43 IDirect3DSurface9_AddRef(iface);
44 *ppobj = This;
45 return S_OK;
46 }
47
48 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
49 *ppobj = NULL;
50 return E_NOINTERFACE;
51}
52
53static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
54 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
55
56 TRACE("(%p)\n", This);
57
58 if (This->forwardReference) {
59 /* Forward refcounting */
60 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
61 return IUnknown_AddRef(This->forwardReference);
62 } else {
63 /* No container, handle our own refcounting */
64 ULONG ref = InterlockedIncrement(&This->ref);
65 if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
66 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
67
68 return ref;
69 }
70
71}
72
73static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
74 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
75
76 TRACE("(%p)\n", This);
77
78 if (This->forwardReference) {
79 /* Forward to the containerParent */
80 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
81 return IUnknown_Release(This->forwardReference);
82 } else {
83 /* No container, handle our own refcounting */
84 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
86
87 if (ref == 0) {
88 if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
89 if (!This->isImplicit) {
90 EnterCriticalSection(&d3d9_cs);
91 IWineD3DSurface_Release(This->wineD3DSurface);
92 LeaveCriticalSection(&d3d9_cs);
93 HeapFree(GetProcessHeap(), 0, This);
94 }
95 }
96
97 return ref;
98 }
99}
100
101/* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
102static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface, IDirect3DDevice9** ppDevice) {
103 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
104 IWineD3DDevice *wined3d_device;
105 HRESULT hr;
106 TRACE("(%p)->(%p)\n", This, ppDevice);
107
108 EnterCriticalSection(&d3d9_cs);
109 hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
110 if (SUCCEEDED(hr))
111 {
112 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
113 IWineD3DDevice_Release(wined3d_device);
114 }
115 LeaveCriticalSection(&d3d9_cs);
116 return hr;
117}
118
119static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
120 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
121 HRESULT hr;
122 TRACE("(%p) Relay\n", This);
123
124 EnterCriticalSection(&d3d9_cs);
125 hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
126 LeaveCriticalSection(&d3d9_cs);
127 return hr;
128}
129
130static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
131 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
132 HRESULT hr;
133 TRACE("(%p) Relay\n", This);
134
135 EnterCriticalSection(&d3d9_cs);
136 hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
137 LeaveCriticalSection(&d3d9_cs);
138 return hr;
139}
140
141static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
142 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
143 HRESULT hr;
144 TRACE("(%p) Relay\n", This);
145
146 EnterCriticalSection(&d3d9_cs);
147 hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
148 LeaveCriticalSection(&d3d9_cs);
149 return hr;
150}
151
152static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
153 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
154 HRESULT hr;
155 TRACE("(%p) Relay\n", This);
156
157 EnterCriticalSection(&d3d9_cs);
158 hr = IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
159 LeaveCriticalSection(&d3d9_cs);
160 return hr;
161}
162
163static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
164 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
165 HRESULT hr;
166 TRACE("(%p) Relay\n", This);
167
168 EnterCriticalSection(&d3d9_cs);
169 hr = IWineD3DSurface_GetPriority(This->wineD3DSurface);
170 LeaveCriticalSection(&d3d9_cs);
171 return hr;
172}
173
174static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
175 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
176 TRACE("(%p) Relay\n", This);
177
178 EnterCriticalSection(&d3d9_cs);
179 IWineD3DSurface_PreLoad(This->wineD3DSurface);
180 LeaveCriticalSection(&d3d9_cs);
181 return ;
182}
183
184static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
185 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
186 D3DRESOURCETYPE ret;
187 TRACE("(%p) Relay\n", This);
188
189 EnterCriticalSection(&d3d9_cs);
190 ret = IWineD3DSurface_GetType(This->wineD3DSurface);
191 LeaveCriticalSection(&d3d9_cs);
192 return ret;
193}
194
195/* IDirect3DSurface9 Interface follow: */
196static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
197 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
198 HRESULT res;
199
200 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
201
202 if (!This->container) return E_NOINTERFACE;
203
204 if (!ppContainer) {
205 ERR("Called without a valid ppContainer\n");
206 }
207
208 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
209
210 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
211
212 return res;
213}
214
215static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
216 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
217 WINED3DSURFACE_DESC wined3ddesc;
218 UINT tmpInt = -1;
219 WINED3DFORMAT format;
220 HRESULT hr;
221 TRACE("(%p) Relay\n", This);
222
223 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
224 wined3ddesc.Format = &format;
225 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
226 wined3ddesc.Usage = &pDesc->Usage;
227 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
228 wined3ddesc.Size = &tmpInt;
229 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
230 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
231 wined3ddesc.Width = &pDesc->Width;
232 wined3ddesc.Height = &pDesc->Height;
233
234 EnterCriticalSection(&d3d9_cs);
235 hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
236 LeaveCriticalSection(&d3d9_cs);
237
238 if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
239
240 return hr;
241}
242
243static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
244 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
245 HRESULT hr;
246 TRACE("(%p) Relay\n", This);
247
248 EnterCriticalSection(&d3d9_cs);
249 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
250 hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
251 LeaveCriticalSection(&d3d9_cs);
252 return hr;
253}
254
255static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
256 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
257 HRESULT hr;
258 TRACE("(%p) Relay\n", This);
259
260 EnterCriticalSection(&d3d9_cs);
261 hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
262 LeaveCriticalSection(&d3d9_cs);
263 switch(hr)
264 {
265 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
266 default: return hr;
267 }
268}
269
270static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
271 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
272 HRESULT hr;
273 TRACE("(%p) Relay\n", This);
274
275 EnterCriticalSection(&d3d9_cs);
276 hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
277 LeaveCriticalSection(&d3d9_cs);
278 return hr;
279}
280
281static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
282 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
283 HRESULT hr;
284 TRACE("(%p) Relay\n", This);
285
286 EnterCriticalSection(&d3d9_cs);
287 hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
288 LeaveCriticalSection(&d3d9_cs);
289 switch(hr) {
290 case WINEDDERR_NODC: return WINED3DERR_INVALIDCALL;
291 default: return hr;
292 }
293}
294
295
296const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
297{
298 /* IUnknown */
299 IDirect3DSurface9Impl_QueryInterface,
300 IDirect3DSurface9Impl_AddRef,
301 IDirect3DSurface9Impl_Release,
302 /* IDirect3DResource9 */
303 IDirect3DSurface9Impl_GetDevice,
304 IDirect3DSurface9Impl_SetPrivateData,
305 IDirect3DSurface9Impl_GetPrivateData,
306 IDirect3DSurface9Impl_FreePrivateData,
307 IDirect3DSurface9Impl_SetPriority,
308 IDirect3DSurface9Impl_GetPriority,
309 IDirect3DSurface9Impl_PreLoad,
310 IDirect3DSurface9Impl_GetType,
311 /* IDirect3DSurface9 */
312 IDirect3DSurface9Impl_GetContainer,
313 IDirect3DSurface9Impl_GetDesc,
314 IDirect3DSurface9Impl_LockRect,
315 IDirect3DSurface9Impl_UnlockRect,
316 IDirect3DSurface9Impl_GetDC,
317 IDirect3DSurface9Impl_ReleaseDC
318};
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