1 | /*
|
---|
2 | * IDirect3DSurface8 implementation
|
---|
3 | *
|
---|
4 | * Copyright 2005 Oliver Stieber
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Lesser General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2.1 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Lesser General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Lesser General Public
|
---|
17 | * License along with this library; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
19 | */
|
---|
20 |
|
---|
21 | /*
|
---|
22 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
23 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
24 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
25 | * a choice of LGPL license versions is made available with the language indicating
|
---|
26 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
27 | * of the LGPL is applied is otherwise unspecified.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #include "config.h"
|
---|
31 | #include "d3d8_private.h"
|
---|
32 |
|
---|
33 | WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
---|
34 |
|
---|
35 | /* IDirect3DSurface8 IUnknown parts follow: */
|
---|
36 | static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface, REFIID riid, LPVOID *ppobj) {
|
---|
37 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
38 |
|
---|
39 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
40 | || IsEqualGUID(riid, &IID_IDirect3DResource8)
|
---|
41 | || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
|
---|
42 | IUnknown_AddRef(iface);
|
---|
43 | *ppobj = This;
|
---|
44 | return S_OK;
|
---|
45 | }
|
---|
46 |
|
---|
47 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
48 | *ppobj = NULL;
|
---|
49 | return E_NOINTERFACE;
|
---|
50 | }
|
---|
51 |
|
---|
52 | static ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
|
---|
53 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
54 |
|
---|
55 | TRACE("(%p)\n", This);
|
---|
56 |
|
---|
57 | if (This->forwardReference) {
|
---|
58 | /* Forward refcounting */
|
---|
59 | TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
|
---|
60 | return IUnknown_AddRef(This->forwardReference);
|
---|
61 | } else {
|
---|
62 | /* No container, handle our own refcounting */
|
---|
63 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
64 | if (ref == 1)
|
---|
65 | {
|
---|
66 | if (This->parentDevice) IUnknown_AddRef(This->parentDevice);
|
---|
67 | wined3d_mutex_lock();
|
---|
68 | IUnknown_AddRef(This->wineD3DSurface);
|
---|
69 | wined3d_mutex_unlock();
|
---|
70 | }
|
---|
71 | TRACE("(%p) : AddRef from %d\n", This, ref - 1);
|
---|
72 | return ref;
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
|
---|
77 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
78 |
|
---|
79 | TRACE("(%p)\n", This);
|
---|
80 |
|
---|
81 | if (This->forwardReference) {
|
---|
82 | /* Forward refcounting */
|
---|
83 | TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
|
---|
84 | return IUnknown_Release(This->forwardReference);
|
---|
85 | } else {
|
---|
86 | /* No container, handle our own refcounting */
|
---|
87 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
88 | TRACE("(%p) : ReleaseRef to %d\n", This, ref);
|
---|
89 |
|
---|
90 | if (ref == 0) {
|
---|
91 | if (This->parentDevice) IUnknown_Release(This->parentDevice);
|
---|
92 | /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
|
---|
93 | wined3d_mutex_lock();
|
---|
94 | IWineD3DSurface_Release(This->wineD3DSurface);
|
---|
95 | wined3d_mutex_unlock();
|
---|
96 | }
|
---|
97 |
|
---|
98 | return ref;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
|
---|
103 | static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8 **ppDevice) {
|
---|
104 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
105 | IWineD3DDevice *wined3d_device;
|
---|
106 | HRESULT hr;
|
---|
107 | TRACE("(%p)->(%p)\n", This, ppDevice);
|
---|
108 |
|
---|
109 | wined3d_mutex_lock();
|
---|
110 | hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
|
---|
111 | if (SUCCEEDED(hr))
|
---|
112 | {
|
---|
113 | IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
|
---|
114 | IWineD3DDevice_Release(wined3d_device);
|
---|
115 | }
|
---|
116 | wined3d_mutex_unlock();
|
---|
117 |
|
---|
118 | return hr;
|
---|
119 | }
|
---|
120 |
|
---|
121 | static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
|
---|
122 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
123 | HRESULT hr;
|
---|
124 | TRACE("(%p) Relay\n", This);
|
---|
125 |
|
---|
126 | wined3d_mutex_lock();
|
---|
127 | hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
|
---|
128 | wined3d_mutex_unlock();
|
---|
129 |
|
---|
130 | return hr;
|
---|
131 | }
|
---|
132 |
|
---|
133 | static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
|
---|
134 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
135 | HRESULT hr;
|
---|
136 | TRACE("(%p) Relay\n", This);
|
---|
137 |
|
---|
138 | wined3d_mutex_lock();
|
---|
139 | hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
|
---|
140 | wined3d_mutex_unlock();
|
---|
141 |
|
---|
142 | return hr;
|
---|
143 | }
|
---|
144 |
|
---|
145 | static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
|
---|
146 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
147 | HRESULT hr;
|
---|
148 | TRACE("(%p) Relay\n", This);
|
---|
149 |
|
---|
150 | wined3d_mutex_lock();
|
---|
151 | hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
|
---|
152 | wined3d_mutex_unlock();
|
---|
153 |
|
---|
154 | return hr;
|
---|
155 | }
|
---|
156 |
|
---|
157 | /* IDirect3DSurface8 Interface follow: */
|
---|
158 | static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) {
|
---|
159 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
160 | HRESULT res;
|
---|
161 |
|
---|
162 | TRACE("(%p) Relay\n", This);
|
---|
163 |
|
---|
164 | if (!This->container) return E_NOINTERFACE;
|
---|
165 |
|
---|
166 | res = IUnknown_QueryInterface(This->container, riid, ppContainer);
|
---|
167 |
|
---|
168 | TRACE("(%p) : returning %p\n", This, *ppContainer);
|
---|
169 | return res;
|
---|
170 | }
|
---|
171 |
|
---|
172 | static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
|
---|
173 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
174 | WINED3DSURFACE_DESC wined3ddesc;
|
---|
175 | HRESULT hr;
|
---|
176 | TRACE("(%p) Relay\n", This);
|
---|
177 |
|
---|
178 | wined3d_mutex_lock();
|
---|
179 | hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
|
---|
180 | wined3d_mutex_unlock();
|
---|
181 |
|
---|
182 | if (SUCCEEDED(hr))
|
---|
183 | {
|
---|
184 | pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
|
---|
185 | pDesc->Type = wined3ddesc.resource_type;
|
---|
186 | pDesc->Usage = wined3ddesc.usage;
|
---|
187 | pDesc->Pool = wined3ddesc.pool;
|
---|
188 | pDesc->Size = wined3ddesc.size;
|
---|
189 | pDesc->MultiSampleType = wined3ddesc.multisample_type;
|
---|
190 | pDesc->Width = wined3ddesc.width;
|
---|
191 | pDesc->Height = wined3ddesc.height;
|
---|
192 | }
|
---|
193 |
|
---|
194 | return hr;
|
---|
195 | }
|
---|
196 |
|
---|
197 | static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
|
---|
198 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
199 | HRESULT hr;
|
---|
200 | TRACE("(%p) Relay\n", This);
|
---|
201 | TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
|
---|
202 |
|
---|
203 | wined3d_mutex_lock();
|
---|
204 | if (pRect) {
|
---|
205 | D3DSURFACE_DESC desc;
|
---|
206 | IDirect3DSurface8_GetDesc(iface, &desc);
|
---|
207 |
|
---|
208 | if ((pRect->left < 0)
|
---|
209 | || (pRect->top < 0)
|
---|
210 | || (pRect->left >= pRect->right)
|
---|
211 | || (pRect->top >= pRect->bottom)
|
---|
212 | || (pRect->right > desc.Width)
|
---|
213 | || (pRect->bottom > desc.Height)) {
|
---|
214 | WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
|
---|
215 | wined3d_mutex_unlock();
|
---|
216 |
|
---|
217 | return D3DERR_INVALIDCALL;
|
---|
218 | }
|
---|
219 | }
|
---|
220 |
|
---|
221 | hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
|
---|
222 | wined3d_mutex_unlock();
|
---|
223 |
|
---|
224 | return hr;
|
---|
225 | }
|
---|
226 |
|
---|
227 | static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
|
---|
228 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
229 | HRESULT hr;
|
---|
230 | TRACE("(%p) Relay\n", This);
|
---|
231 |
|
---|
232 | wined3d_mutex_lock();
|
---|
233 | hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
|
---|
234 | wined3d_mutex_unlock();
|
---|
235 |
|
---|
236 | switch(hr)
|
---|
237 | {
|
---|
238 | case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
|
---|
239 | default: return hr;
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | static const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
|
---|
244 | {
|
---|
245 | /* IUnknown */
|
---|
246 | IDirect3DSurface8Impl_QueryInterface,
|
---|
247 | IDirect3DSurface8Impl_AddRef,
|
---|
248 | IDirect3DSurface8Impl_Release,
|
---|
249 | /* IDirect3DResource8 */
|
---|
250 | IDirect3DSurface8Impl_GetDevice,
|
---|
251 | IDirect3DSurface8Impl_SetPrivateData,
|
---|
252 | IDirect3DSurface8Impl_GetPrivateData,
|
---|
253 | IDirect3DSurface8Impl_FreePrivateData,
|
---|
254 | /* IDirect3DSurface8 */
|
---|
255 | IDirect3DSurface8Impl_GetContainer,
|
---|
256 | IDirect3DSurface8Impl_GetDesc,
|
---|
257 | IDirect3DSurface8Impl_LockRect,
|
---|
258 | IDirect3DSurface8Impl_UnlockRect
|
---|
259 | };
|
---|
260 |
|
---|
261 | static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
|
---|
262 | {
|
---|
263 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
264 | }
|
---|
265 |
|
---|
266 | static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
|
---|
267 | {
|
---|
268 | surface_wined3d_object_destroyed,
|
---|
269 | };
|
---|
270 |
|
---|
271 | HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
|
---|
272 | UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
|
---|
273 | DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
|
---|
274 | {
|
---|
275 | HRESULT hr;
|
---|
276 |
|
---|
277 | surface->lpVtbl = &Direct3DSurface8_Vtbl;
|
---|
278 | surface->ref = 1;
|
---|
279 |
|
---|
280 | /* FIXME: Check MAX bounds of MultisampleQuality. */
|
---|
281 | if (multisample_quality > 0)
|
---|
282 | {
|
---|
283 | FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
|
---|
284 | multisample_quality = 0;
|
---|
285 | }
|
---|
286 |
|
---|
287 | wined3d_mutex_lock();
|
---|
288 | hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
|
---|
289 | lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
|
---|
290 | multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface,
|
---|
291 | &d3d8_surface_wined3d_parent_ops);
|
---|
292 | wined3d_mutex_unlock();
|
---|
293 | if (FAILED(hr))
|
---|
294 | {
|
---|
295 | WARN("Failed to create wined3d surface, hr %#x.\n", hr);
|
---|
296 | return hr;
|
---|
297 | }
|
---|
298 |
|
---|
299 | surface->parentDevice = (IDirect3DDevice8 *)device;
|
---|
300 | IUnknown_AddRef(surface->parentDevice);
|
---|
301 |
|
---|
302 | return D3D_OK;
|
---|
303 | }
|
---|