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 |
|
---|
34 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
35 |
|
---|
36 | /* IDirect3DSurface9 IUnknown parts follow: */
|
---|
37 | static 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 |
|
---|
53 | static 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 |
|
---|
73 | static 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: */
|
---|
102 | static 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 |
|
---|
119 | static 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 |
|
---|
130 | static 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 |
|
---|
141 | static 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 |
|
---|
152 | static 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 |
|
---|
163 | static 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 |
|
---|
174 | static 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 |
|
---|
184 | static 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: */
|
---|
196 | static 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 |
|
---|
215 | static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
|
---|
216 | IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
|
---|
217 | WINED3DSURFACE_DESC wined3ddesc;
|
---|
218 | HRESULT hr;
|
---|
219 | TRACE("(%p) Relay\n", This);
|
---|
220 |
|
---|
221 | EnterCriticalSection(&d3d9_cs);
|
---|
222 | hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
|
---|
223 | LeaveCriticalSection(&d3d9_cs);
|
---|
224 |
|
---|
225 | if (SUCCEEDED(hr))
|
---|
226 | {
|
---|
227 | pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
|
---|
228 | pDesc->Type = wined3ddesc.resource_type;
|
---|
229 | pDesc->Usage = wined3ddesc.usage;
|
---|
230 | pDesc->Pool = wined3ddesc.pool;
|
---|
231 | pDesc->MultiSampleType = wined3ddesc.multisample_type;
|
---|
232 | pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
|
---|
233 | pDesc->Width = wined3ddesc.width;
|
---|
234 | pDesc->Height = wined3ddesc.height;
|
---|
235 | }
|
---|
236 |
|
---|
237 | return hr;
|
---|
238 | }
|
---|
239 |
|
---|
240 | static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
|
---|
241 | IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
|
---|
242 | HRESULT hr;
|
---|
243 | TRACE("(%p) Relay\n", This);
|
---|
244 |
|
---|
245 | EnterCriticalSection(&d3d9_cs);
|
---|
246 | TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
|
---|
247 | hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
|
---|
248 | LeaveCriticalSection(&d3d9_cs);
|
---|
249 | return hr;
|
---|
250 | }
|
---|
251 |
|
---|
252 | static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
|
---|
253 | IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
|
---|
254 | HRESULT hr;
|
---|
255 | TRACE("(%p) Relay\n", This);
|
---|
256 |
|
---|
257 | EnterCriticalSection(&d3d9_cs);
|
---|
258 | hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
|
---|
259 | LeaveCriticalSection(&d3d9_cs);
|
---|
260 | switch(hr)
|
---|
261 | {
|
---|
262 | case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
|
---|
263 | default: return hr;
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
|
---|
268 | IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
|
---|
269 | HRESULT hr;
|
---|
270 | TRACE("(%p) Relay\n", This);
|
---|
271 |
|
---|
272 | EnterCriticalSection(&d3d9_cs);
|
---|
273 | hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
|
---|
274 | LeaveCriticalSection(&d3d9_cs);
|
---|
275 | return hr;
|
---|
276 | }
|
---|
277 |
|
---|
278 | static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
|
---|
279 | IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
|
---|
280 | HRESULT hr;
|
---|
281 | TRACE("(%p) Relay\n", This);
|
---|
282 |
|
---|
283 | EnterCriticalSection(&d3d9_cs);
|
---|
284 | hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
|
---|
285 | LeaveCriticalSection(&d3d9_cs);
|
---|
286 | switch(hr) {
|
---|
287 | case WINEDDERR_NODC: return WINED3DERR_INVALIDCALL;
|
---|
288 | default: return hr;
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 |
|
---|
293 | const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
|
---|
294 | {
|
---|
295 | /* IUnknown */
|
---|
296 | IDirect3DSurface9Impl_QueryInterface,
|
---|
297 | IDirect3DSurface9Impl_AddRef,
|
---|
298 | IDirect3DSurface9Impl_Release,
|
---|
299 | /* IDirect3DResource9 */
|
---|
300 | IDirect3DSurface9Impl_GetDevice,
|
---|
301 | IDirect3DSurface9Impl_SetPrivateData,
|
---|
302 | IDirect3DSurface9Impl_GetPrivateData,
|
---|
303 | IDirect3DSurface9Impl_FreePrivateData,
|
---|
304 | IDirect3DSurface9Impl_SetPriority,
|
---|
305 | IDirect3DSurface9Impl_GetPriority,
|
---|
306 | IDirect3DSurface9Impl_PreLoad,
|
---|
307 | IDirect3DSurface9Impl_GetType,
|
---|
308 | /* IDirect3DSurface9 */
|
---|
309 | IDirect3DSurface9Impl_GetContainer,
|
---|
310 | IDirect3DSurface9Impl_GetDesc,
|
---|
311 | IDirect3DSurface9Impl_LockRect,
|
---|
312 | IDirect3DSurface9Impl_UnlockRect,
|
---|
313 | IDirect3DSurface9Impl_GetDC,
|
---|
314 | IDirect3DSurface9Impl_ReleaseDC
|
---|
315 | };
|
---|