VirtualBox

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

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

LGPL disclaimer by filemuncher

  • Property svn:eol-style set to native
File size: 10.8 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 HRESULT hr;
105 TRACE("(%p)->(%p)\n", This, ppDevice);
106
107 EnterCriticalSection(&d3d9_cs);
108 hr = IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
109 LeaveCriticalSection(&d3d9_cs);
110 return hr;
111}
112
113static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
114 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
115 HRESULT hr;
116 TRACE("(%p) Relay\n", This);
117
118 EnterCriticalSection(&d3d9_cs);
119 hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
120 LeaveCriticalSection(&d3d9_cs);
121 return hr;
122}
123
124static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
125 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
126 HRESULT hr;
127 TRACE("(%p) Relay\n", This);
128
129 EnterCriticalSection(&d3d9_cs);
130 hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
131 LeaveCriticalSection(&d3d9_cs);
132 return hr;
133}
134
135static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
136 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
137 HRESULT hr;
138 TRACE("(%p) Relay\n", This);
139
140 EnterCriticalSection(&d3d9_cs);
141 hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
142 LeaveCriticalSection(&d3d9_cs);
143 return hr;
144}
145
146static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
147 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
148 HRESULT hr;
149 TRACE("(%p) Relay\n", This);
150
151 EnterCriticalSection(&d3d9_cs);
152 hr = IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
153 LeaveCriticalSection(&d3d9_cs);
154 return hr;
155}
156
157static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
158 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
159 HRESULT hr;
160 TRACE("(%p) Relay\n", This);
161
162 EnterCriticalSection(&d3d9_cs);
163 hr = IWineD3DSurface_GetPriority(This->wineD3DSurface);
164 LeaveCriticalSection(&d3d9_cs);
165 return hr;
166}
167
168static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
169 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
170 TRACE("(%p) Relay\n", This);
171
172 EnterCriticalSection(&d3d9_cs);
173 IWineD3DSurface_PreLoad(This->wineD3DSurface);
174 LeaveCriticalSection(&d3d9_cs);
175 return ;
176}
177
178static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface) {
179 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
180 D3DRESOURCETYPE ret;
181 TRACE("(%p) Relay\n", This);
182
183 EnterCriticalSection(&d3d9_cs);
184 ret = IWineD3DSurface_GetType(This->wineD3DSurface);
185 LeaveCriticalSection(&d3d9_cs);
186 return ret;
187}
188
189/* IDirect3DSurface9 Interface follow: */
190static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
191 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
192 HRESULT res;
193
194 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
195
196 if (!This->container) return E_NOINTERFACE;
197
198 if (!ppContainer) {
199 ERR("Called without a valid ppContainer\n");
200 }
201
202 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
203
204 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
205
206 return res;
207}
208
209static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
210 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
211 WINED3DSURFACE_DESC wined3ddesc;
212 UINT tmpInt = -1;
213 HRESULT hr;
214 TRACE("(%p) Relay\n", This);
215
216 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
217 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
218 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
219 wined3ddesc.Usage = &pDesc->Usage;
220 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
221 wined3ddesc.Size = &tmpInt;
222 wined3ddesc.MultiSampleType = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
223 wined3ddesc.MultiSampleQuality = &pDesc->MultiSampleQuality;
224 wined3ddesc.Width = &pDesc->Width;
225 wined3ddesc.Height = &pDesc->Height;
226
227 EnterCriticalSection(&d3d9_cs);
228 hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
229 LeaveCriticalSection(&d3d9_cs);
230 return hr;
231}
232
233static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
234 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
235 HRESULT hr;
236 TRACE("(%p) Relay\n", This);
237
238 EnterCriticalSection(&d3d9_cs);
239 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
240 hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
241 LeaveCriticalSection(&d3d9_cs);
242 return hr;
243}
244
245static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
246 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
247 HRESULT hr;
248 TRACE("(%p) Relay\n", This);
249
250 EnterCriticalSection(&d3d9_cs);
251 hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
252 LeaveCriticalSection(&d3d9_cs);
253 return hr;
254}
255
256static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
257 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
258 HRESULT hr;
259 TRACE("(%p) Relay\n", This);
260
261 EnterCriticalSection(&d3d9_cs);
262 hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
263 LeaveCriticalSection(&d3d9_cs);
264 return hr;
265}
266
267static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
268 IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
269 HRESULT hr;
270 TRACE("(%p) Relay\n", This);
271
272 EnterCriticalSection(&d3d9_cs);
273 hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
274 LeaveCriticalSection(&d3d9_cs);
275 return hr;
276}
277
278
279const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
280{
281 /* IUnknown */
282 IDirect3DSurface9Impl_QueryInterface,
283 IDirect3DSurface9Impl_AddRef,
284 IDirect3DSurface9Impl_Release,
285 /* IDirect3DResource9 */
286 IDirect3DSurface9Impl_GetDevice,
287 IDirect3DSurface9Impl_SetPrivateData,
288 IDirect3DSurface9Impl_GetPrivateData,
289 IDirect3DSurface9Impl_FreePrivateData,
290 IDirect3DSurface9Impl_SetPriority,
291 IDirect3DSurface9Impl_GetPriority,
292 IDirect3DSurface9Impl_PreLoad,
293 IDirect3DSurface9Impl_GetType,
294 /* IDirect3DSurface9 */
295 IDirect3DSurface9Impl_GetContainer,
296 IDirect3DSurface9Impl_GetDesc,
297 IDirect3DSurface9Impl_LockRect,
298 IDirect3DSurface9Impl_UnlockRect,
299 IDirect3DSurface9Impl_GetDC,
300 IDirect3DSurface9Impl_ReleaseDC
301};
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