VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/d3d8/surface.c@ 48345

Last change on this file since 48345 was 48345, checked in by vboxsync, 11 years ago

header fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 KB
Line 
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
33WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
34
35static inline struct d3d8_surface *impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface)
36{
37 return CONTAINING_RECORD(iface, struct d3d8_surface, IDirect3DSurface8_iface);
38}
39
40static HRESULT WINAPI d3d8_surface_QueryInterface(IDirect3DSurface8 *iface, REFIID riid, void **out)
41{
42 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), out);
43
44 if (IsEqualGUID(riid, &IID_IDirect3DSurface8)
45 || IsEqualGUID(riid, &IID_IDirect3DResource8)
46 || IsEqualGUID(riid, &IID_IUnknown))
47 {
48 IDirect3DSurface8_AddRef(iface);
49 *out = iface;
50 return S_OK;
51 }
52
53 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
54
55 *out = NULL;
56 return E_NOINTERFACE;
57}
58
59static ULONG WINAPI d3d8_surface_AddRef(IDirect3DSurface8 *iface)
60{
61 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
62
63 TRACE("iface %p.\n", iface);
64
65 if (surface->forwardReference)
66 {
67 /* Forward refcounting */
68 TRACE("Forwarding to %p.\n", surface->forwardReference);
69 return IUnknown_AddRef(surface->forwardReference);
70 }
71 else
72 {
73 /* No container, handle our own refcounting */
74 ULONG ref = InterlockedIncrement(&surface->refcount);
75
76 TRACE("%p increasing refcount to %u.\n", iface, ref);
77
78 if (ref == 1)
79 {
80 if (surface->parent_device)
81 IDirect3DDevice8_AddRef(surface->parent_device);
82 wined3d_mutex_lock();
83 wined3d_surface_incref(surface->wined3d_surface);
84 wined3d_mutex_unlock();
85 }
86
87 return ref;
88 }
89}
90
91static ULONG WINAPI d3d8_surface_Release(IDirect3DSurface8 *iface)
92{
93 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
94
95 TRACE("iface %p.\n", iface);
96
97 if (surface->forwardReference)
98 {
99 /* Forward refcounting */
100 TRACE("Forwarding to %p.\n", surface->forwardReference);
101 return IUnknown_Release(surface->forwardReference);
102 }
103 else
104 {
105 /* No container, handle our own refcounting */
106 ULONG ref = InterlockedDecrement(&surface->refcount);
107
108 TRACE("%p decreasing refcount to %u.\n", iface, ref);
109
110 if (!ref)
111 {
112 IDirect3DDevice8 *parent_device = surface->parent_device;
113
114 /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
115 wined3d_mutex_lock();
116 wined3d_surface_decref(surface->wined3d_surface);
117 wined3d_mutex_unlock();
118
119 if (parent_device)
120 IDirect3DDevice8_Release(parent_device);
121 }
122
123 return ref;
124 }
125}
126
127static HRESULT WINAPI d3d8_surface_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device)
128{
129 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
130
131 TRACE("iface %p, device %p.\n", iface, device);
132
133 if (surface->forwardReference)
134 {
135 IDirect3DResource8 *resource;
136 HRESULT hr;
137
138 hr = IUnknown_QueryInterface(surface->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
139 if (SUCCEEDED(hr))
140 {
141 hr = IDirect3DResource8_GetDevice(resource, device);
142 IDirect3DResource8_Release(resource);
143
144 TRACE("Returning device %p.\n", *device);
145 }
146
147 return hr;
148 }
149
150 *device = surface->parent_device;
151 IDirect3DDevice8_AddRef(*device);
152
153 TRACE("Returning device %p.\n", *device);
154
155 return D3D_OK;
156}
157
158static HRESULT WINAPI d3d8_surface_SetPrivateData(IDirect3DSurface8 *iface, REFGUID guid,
159 const void *data, DWORD data_size, DWORD flags)
160{
161 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
162 struct wined3d_resource *resource;
163 HRESULT hr;
164
165 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
166 iface, debugstr_guid(guid), data, data_size, flags);
167
168 wined3d_mutex_lock();
169 resource = wined3d_surface_get_resource(surface->wined3d_surface);
170 hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
171 wined3d_mutex_unlock();
172
173 return hr;
174}
175
176static HRESULT WINAPI d3d8_surface_GetPrivateData(IDirect3DSurface8 *iface, REFGUID guid,
177 void *data, DWORD *data_size)
178{
179 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
180 struct wined3d_resource *resource;
181 HRESULT hr;
182
183 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
184 iface, debugstr_guid(guid), data, data_size);
185
186 wined3d_mutex_lock();
187 resource = wined3d_surface_get_resource(surface->wined3d_surface);
188 hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
189 wined3d_mutex_unlock();
190
191 return hr;
192}
193
194static HRESULT WINAPI d3d8_surface_FreePrivateData(IDirect3DSurface8 *iface, REFGUID guid)
195{
196 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
197 struct wined3d_resource *resource;
198 HRESULT hr;
199
200 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
201
202 wined3d_mutex_lock();
203 resource = wined3d_surface_get_resource(surface->wined3d_surface);
204 hr = wined3d_resource_free_private_data(resource, guid);
205 wined3d_mutex_unlock();
206
207 return hr;
208}
209
210static HRESULT WINAPI d3d8_surface_GetContainer(IDirect3DSurface8 *iface, REFIID riid, void **container)
211{
212 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
213 HRESULT hr;
214
215 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), container);
216
217 if (!surface->container)
218 return E_NOINTERFACE;
219
220 hr = IUnknown_QueryInterface(surface->container, riid, container);
221
222 TRACE("Returning %p.\n", *container);
223
224 return hr;
225}
226
227static HRESULT WINAPI d3d8_surface_GetDesc(IDirect3DSurface8 *iface, D3DSURFACE_DESC *desc)
228{
229 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
230 struct wined3d_resource_desc wined3d_desc;
231 struct wined3d_resource *wined3d_resource;
232
233 TRACE("iface %p, desc %p.\n", iface, desc);
234
235 wined3d_mutex_lock();
236 wined3d_resource = wined3d_surface_get_resource(surface->wined3d_surface);
237 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
238 wined3d_mutex_unlock();
239
240 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
241 desc->Type = wined3d_desc.resource_type;
242 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
243 desc->Pool = wined3d_desc.pool;
244 desc->Size = wined3d_desc.size;
245 desc->MultiSampleType = wined3d_desc.multisample_type;
246 desc->Width = wined3d_desc.width;
247 desc->Height = wined3d_desc.height;
248
249 return D3D_OK;
250}
251
252static HRESULT WINAPI d3d8_surface_LockRect(IDirect3DSurface8 *iface,
253 D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
254{
255 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
256 struct wined3d_map_desc map_desc;
257 HRESULT hr;
258
259 TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n",
260 iface, locked_rect, wine_dbgstr_rect(rect), flags);
261
262 wined3d_mutex_lock();
263 if (rect)
264 {
265 D3DSURFACE_DESC desc;
266 IDirect3DSurface8_GetDesc(iface, &desc);
267
268 if ((rect->left < 0)
269 || (rect->top < 0)
270 || (rect->left >= rect->right)
271 || (rect->top >= rect->bottom)
272 || (rect->right > desc.Width)
273 || (rect->bottom > desc.Height))
274 {
275 WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
276 wined3d_mutex_unlock();
277
278 return D3DERR_INVALIDCALL;
279 }
280 }
281
282 hr = wined3d_surface_map(surface->wined3d_surface, &map_desc, rect, flags);
283 wined3d_mutex_unlock();
284
285 locked_rect->Pitch = map_desc.row_pitch;
286 locked_rect->pBits = map_desc.data;
287
288 return hr;
289}
290
291static HRESULT WINAPI d3d8_surface_UnlockRect(IDirect3DSurface8 *iface)
292{
293 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
294 HRESULT hr;
295
296 TRACE("iface %p.\n", iface);
297
298 wined3d_mutex_lock();
299 hr = wined3d_surface_unmap(surface->wined3d_surface);
300 wined3d_mutex_unlock();
301
302 switch(hr)
303 {
304 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
305 default: return hr;
306 }
307}
308
309static const IDirect3DSurface8Vtbl d3d8_surface_vtbl =
310{
311 /* IUnknown */
312 d3d8_surface_QueryInterface,
313 d3d8_surface_AddRef,
314 d3d8_surface_Release,
315 /* IDirect3DResource8 */
316 d3d8_surface_GetDevice,
317 d3d8_surface_SetPrivateData,
318 d3d8_surface_GetPrivateData,
319 d3d8_surface_FreePrivateData,
320 /* IDirect3DSurface8 */
321 d3d8_surface_GetContainer,
322 d3d8_surface_GetDesc,
323 d3d8_surface_LockRect,
324 d3d8_surface_UnlockRect,
325};
326
327static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
328{
329 HeapFree(GetProcessHeap(), 0, parent);
330}
331
332static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
333{
334 surface_wined3d_object_destroyed,
335};
336
337HRESULT surface_init(struct d3d8_surface *surface, struct d3d8_device *device, UINT width, UINT height,
338 D3DFORMAT format, DWORD flags, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type,
339 DWORD multisample_quality)
340{
341 HRESULT hr;
342
343 surface->IDirect3DSurface8_iface.lpVtbl = &d3d8_surface_vtbl;
344 surface->refcount = 1;
345
346 /* FIXME: Check MAX bounds of MultisampleQuality. */
347 if (multisample_quality > 0)
348 {
349 FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
350 multisample_quality = 0;
351 }
352
353 wined3d_mutex_lock();
354 hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format),
355 usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality,
356 flags, surface, &d3d8_surface_wined3d_parent_ops, &surface->wined3d_surface);
357 wined3d_mutex_unlock();
358 if (FAILED(hr))
359 {
360 WARN("Failed to create wined3d surface, hr %#x.\n", hr);
361 return hr;
362 }
363
364 surface->parent_device = &device->IDirect3DDevice8_iface;
365 IDirect3DDevice8_AddRef(surface->parent_device);
366
367 return D3D_OK;
368}
369
370struct d3d8_surface *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface)
371{
372 if (!iface)
373 return NULL;
374 assert(iface->lpVtbl == &d3d8_surface_vtbl);
375
376 return impl_from_IDirect3DSurface8(iface);
377}
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