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 | * Oracle 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, Oracle 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 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
|
---|
40 |
|
---|
41 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
42 | || IsEqualGUID(riid, &IID_IDirect3DResource8)
|
---|
43 | || IsEqualGUID(riid, &IID_IDirect3DSurface8)) {
|
---|
44 | IUnknown_AddRef(iface);
|
---|
45 | *ppobj = This;
|
---|
46 | return S_OK;
|
---|
47 | }
|
---|
48 |
|
---|
49 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
50 | *ppobj = NULL;
|
---|
51 | return E_NOINTERFACE;
|
---|
52 | }
|
---|
53 |
|
---|
54 | static ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
|
---|
55 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
56 |
|
---|
57 | TRACE("iface %p.\n", iface);
|
---|
58 |
|
---|
59 | if (This->forwardReference) {
|
---|
60 | /* Forward refcounting */
|
---|
61 | TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
|
---|
62 | return IUnknown_AddRef(This->forwardReference);
|
---|
63 | } else {
|
---|
64 | /* No container, handle our own refcounting */
|
---|
65 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
66 |
|
---|
67 | TRACE("%p increasing refcount to %u.\n", iface, ref);
|
---|
68 |
|
---|
69 | if (ref == 1)
|
---|
70 | {
|
---|
71 | if (This->parentDevice) IUnknown_AddRef(This->parentDevice);
|
---|
72 | wined3d_mutex_lock();
|
---|
73 | IUnknown_AddRef(This->wineD3DSurface);
|
---|
74 | wined3d_mutex_unlock();
|
---|
75 | }
|
---|
76 |
|
---|
77 | return ref;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
|
---|
82 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
83 |
|
---|
84 | TRACE("iface %p.\n", iface);
|
---|
85 |
|
---|
86 | if (This->forwardReference) {
|
---|
87 | /* Forward refcounting */
|
---|
88 | TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
|
---|
89 | return IUnknown_Release(This->forwardReference);
|
---|
90 | } else {
|
---|
91 | /* No container, handle our own refcounting */
|
---|
92 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
93 |
|
---|
94 | TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
---|
95 |
|
---|
96 | if (ref == 0) {
|
---|
97 | IDirect3DDevice8 *parentDevice = This->parentDevice;
|
---|
98 |
|
---|
99 | /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
|
---|
100 | wined3d_mutex_lock();
|
---|
101 | IWineD3DSurface_Release(This->wineD3DSurface);
|
---|
102 | wined3d_mutex_unlock();
|
---|
103 |
|
---|
104 | if (parentDevice) IDirect3DDevice8_Release(parentDevice);
|
---|
105 | }
|
---|
106 |
|
---|
107 | return ref;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
|
---|
112 | static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device)
|
---|
113 | {
|
---|
114 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
115 |
|
---|
116 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
117 |
|
---|
118 | if (This->forwardReference)
|
---|
119 | {
|
---|
120 | IDirect3DResource8 *resource;
|
---|
121 | HRESULT hr;
|
---|
122 |
|
---|
123 | hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
|
---|
124 | if (SUCCEEDED(hr))
|
---|
125 | {
|
---|
126 | hr = IDirect3DResource8_GetDevice(resource, device);
|
---|
127 | IDirect3DResource8_Release(resource);
|
---|
128 |
|
---|
129 | TRACE("Returning device %p.\n", *device);
|
---|
130 | }
|
---|
131 |
|
---|
132 | return hr;
|
---|
133 | }
|
---|
134 |
|
---|
135 | *device = (IDirect3DDevice8 *)This->parentDevice;
|
---|
136 | IDirect3DDevice8_AddRef(*device);
|
---|
137 |
|
---|
138 | TRACE("Returning device %p.\n", *device);
|
---|
139 |
|
---|
140 | return D3D_OK;
|
---|
141 | }
|
---|
142 |
|
---|
143 | static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
|
---|
144 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
145 | HRESULT hr;
|
---|
146 |
|
---|
147 | TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
|
---|
148 | iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
|
---|
149 |
|
---|
150 | wined3d_mutex_lock();
|
---|
151 | hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
|
---|
152 | wined3d_mutex_unlock();
|
---|
153 |
|
---|
154 | return hr;
|
---|
155 | }
|
---|
156 |
|
---|
157 | static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
|
---|
158 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
159 | HRESULT hr;
|
---|
160 |
|
---|
161 | TRACE("iface %p, guid %s, data %p, data_size %p.\n",
|
---|
162 | iface, debugstr_guid(refguid), pData, pSizeOfData);
|
---|
163 |
|
---|
164 | wined3d_mutex_lock();
|
---|
165 | hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
|
---|
166 | wined3d_mutex_unlock();
|
---|
167 |
|
---|
168 | return hr;
|
---|
169 | }
|
---|
170 |
|
---|
171 | static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
|
---|
172 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
173 | HRESULT hr;
|
---|
174 |
|
---|
175 | TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
|
---|
176 |
|
---|
177 | wined3d_mutex_lock();
|
---|
178 | hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
|
---|
179 | wined3d_mutex_unlock();
|
---|
180 |
|
---|
181 | return hr;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /* IDirect3DSurface8 Interface follow: */
|
---|
185 | static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) {
|
---|
186 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
187 | HRESULT res;
|
---|
188 |
|
---|
189 | TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
|
---|
190 |
|
---|
191 | if (!This->container) return E_NOINTERFACE;
|
---|
192 |
|
---|
193 | res = IUnknown_QueryInterface(This->container, riid, ppContainer);
|
---|
194 |
|
---|
195 | TRACE("(%p) : returning %p\n", This, *ppContainer);
|
---|
196 | return res;
|
---|
197 | }
|
---|
198 |
|
---|
199 | static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
|
---|
200 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
201 | WINED3DSURFACE_DESC wined3ddesc;
|
---|
202 | HRESULT hr;
|
---|
203 |
|
---|
204 | TRACE("iface %p, desc %p.\n", iface, pDesc);
|
---|
205 |
|
---|
206 | wined3d_mutex_lock();
|
---|
207 | hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
|
---|
208 | wined3d_mutex_unlock();
|
---|
209 |
|
---|
210 | if (SUCCEEDED(hr))
|
---|
211 | {
|
---|
212 | pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
|
---|
213 | pDesc->Type = wined3ddesc.resource_type;
|
---|
214 | pDesc->Usage = wined3ddesc.usage;
|
---|
215 | pDesc->Pool = wined3ddesc.pool;
|
---|
216 | pDesc->Size = wined3ddesc.size;
|
---|
217 | pDesc->MultiSampleType = wined3ddesc.multisample_type;
|
---|
218 | pDesc->Width = wined3ddesc.width;
|
---|
219 | pDesc->Height = wined3ddesc.height;
|
---|
220 | }
|
---|
221 |
|
---|
222 | return hr;
|
---|
223 | }
|
---|
224 |
|
---|
225 | static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
|
---|
226 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
227 | HRESULT hr;
|
---|
228 |
|
---|
229 | TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags);
|
---|
230 |
|
---|
231 | wined3d_mutex_lock();
|
---|
232 | if (pRect) {
|
---|
233 | D3DSURFACE_DESC desc;
|
---|
234 | IDirect3DSurface8_GetDesc(iface, &desc);
|
---|
235 |
|
---|
236 | if ((pRect->left < 0)
|
---|
237 | || (pRect->top < 0)
|
---|
238 | || (pRect->left >= pRect->right)
|
---|
239 | || (pRect->top >= pRect->bottom)
|
---|
240 | || (pRect->right > desc.Width)
|
---|
241 | || (pRect->bottom > desc.Height)) {
|
---|
242 | WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
|
---|
243 | wined3d_mutex_unlock();
|
---|
244 |
|
---|
245 | return D3DERR_INVALIDCALL;
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
|
---|
250 | wined3d_mutex_unlock();
|
---|
251 |
|
---|
252 | return hr;
|
---|
253 | }
|
---|
254 |
|
---|
255 | static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
|
---|
256 | IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
|
---|
257 | HRESULT hr;
|
---|
258 |
|
---|
259 | TRACE("iface %p.\n", iface);
|
---|
260 |
|
---|
261 | wined3d_mutex_lock();
|
---|
262 | hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
|
---|
263 | wined3d_mutex_unlock();
|
---|
264 |
|
---|
265 | switch(hr)
|
---|
266 | {
|
---|
267 | case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
|
---|
268 | default: return hr;
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | static const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
|
---|
273 | {
|
---|
274 | /* IUnknown */
|
---|
275 | IDirect3DSurface8Impl_QueryInterface,
|
---|
276 | IDirect3DSurface8Impl_AddRef,
|
---|
277 | IDirect3DSurface8Impl_Release,
|
---|
278 | /* IDirect3DResource8 */
|
---|
279 | IDirect3DSurface8Impl_GetDevice,
|
---|
280 | IDirect3DSurface8Impl_SetPrivateData,
|
---|
281 | IDirect3DSurface8Impl_GetPrivateData,
|
---|
282 | IDirect3DSurface8Impl_FreePrivateData,
|
---|
283 | /* IDirect3DSurface8 */
|
---|
284 | IDirect3DSurface8Impl_GetContainer,
|
---|
285 | IDirect3DSurface8Impl_GetDesc,
|
---|
286 | IDirect3DSurface8Impl_LockRect,
|
---|
287 | IDirect3DSurface8Impl_UnlockRect
|
---|
288 | };
|
---|
289 |
|
---|
290 | static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
|
---|
291 | {
|
---|
292 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
293 | }
|
---|
294 |
|
---|
295 | static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
|
---|
296 | {
|
---|
297 | surface_wined3d_object_destroyed,
|
---|
298 | };
|
---|
299 |
|
---|
300 | HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
|
---|
301 | UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
|
---|
302 | DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
|
---|
303 | {
|
---|
304 | HRESULT hr;
|
---|
305 |
|
---|
306 | surface->lpVtbl = &Direct3DSurface8_Vtbl;
|
---|
307 | surface->ref = 1;
|
---|
308 |
|
---|
309 | /* FIXME: Check MAX bounds of MultisampleQuality. */
|
---|
310 | if (multisample_quality > 0)
|
---|
311 | {
|
---|
312 | FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
|
---|
313 | multisample_quality = 0;
|
---|
314 | }
|
---|
315 |
|
---|
316 | wined3d_mutex_lock();
|
---|
317 | hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
|
---|
318 | lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
|
---|
319 | multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface,
|
---|
320 | &d3d8_surface_wined3d_parent_ops);
|
---|
321 | wined3d_mutex_unlock();
|
---|
322 | if (FAILED(hr))
|
---|
323 | {
|
---|
324 | WARN("Failed to create wined3d surface, hr %#x.\n", hr);
|
---|
325 | return hr;
|
---|
326 | }
|
---|
327 |
|
---|
328 | surface->parentDevice = (IDirect3DDevice8 *)device;
|
---|
329 | IUnknown_AddRef(surface->parentDevice);
|
---|
330 |
|
---|
331 | return D3D_OK;
|
---|
332 | }
|
---|