VirtualBox

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

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

wine: update to 1.6.2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 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 if (SUCCEEDED(hr))
286 {
287 locked_rect->Pitch = map_desc.row_pitch;
288 locked_rect->pBits = map_desc.data;
289 }
290 else
291 {
292 locked_rect->Pitch = 0;
293 locked_rect->pBits = NULL;
294 }
295
296 return hr;
297}
298
299static HRESULT WINAPI d3d8_surface_UnlockRect(IDirect3DSurface8 *iface)
300{
301 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
302 HRESULT hr;
303
304 TRACE("iface %p.\n", iface);
305
306 wined3d_mutex_lock();
307 hr = wined3d_surface_unmap(surface->wined3d_surface);
308 wined3d_mutex_unlock();
309
310 switch(hr)
311 {
312 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
313 default: return hr;
314 }
315}
316
317static const IDirect3DSurface8Vtbl d3d8_surface_vtbl =
318{
319 /* IUnknown */
320 d3d8_surface_QueryInterface,
321 d3d8_surface_AddRef,
322 d3d8_surface_Release,
323 /* IDirect3DResource8 */
324 d3d8_surface_GetDevice,
325 d3d8_surface_SetPrivateData,
326 d3d8_surface_GetPrivateData,
327 d3d8_surface_FreePrivateData,
328 /* IDirect3DSurface8 */
329 d3d8_surface_GetContainer,
330 d3d8_surface_GetDesc,
331 d3d8_surface_LockRect,
332 d3d8_surface_UnlockRect,
333};
334
335static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
336{
337 HeapFree(GetProcessHeap(), 0, parent);
338}
339
340static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
341{
342 surface_wined3d_object_destroyed,
343};
344
345HRESULT surface_init(struct d3d8_surface *surface, struct d3d8_device *device, UINT width, UINT height,
346 D3DFORMAT format, DWORD flags, DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type,
347 DWORD multisample_quality)
348{
349 HRESULT hr;
350
351 surface->IDirect3DSurface8_iface.lpVtbl = &d3d8_surface_vtbl;
352 surface->refcount = 1;
353
354 /* FIXME: Check MAX bounds of MultisampleQuality. */
355 if (multisample_quality > 0)
356 {
357 FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
358 multisample_quality = 0;
359 }
360
361 wined3d_mutex_lock();
362 hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format),
363 usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality,
364 flags, surface, &d3d8_surface_wined3d_parent_ops, &surface->wined3d_surface);
365 wined3d_mutex_unlock();
366 if (FAILED(hr))
367 {
368 WARN("Failed to create wined3d surface, hr %#x.\n", hr);
369 return hr;
370 }
371
372 surface->parent_device = &device->IDirect3DDevice8_iface;
373 IDirect3DDevice8_AddRef(surface->parent_device);
374
375 return D3D_OK;
376}
377
378struct d3d8_surface *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface)
379{
380 if (!iface)
381 return NULL;
382 assert(iface->lpVtbl == &d3d8_surface_vtbl);
383
384 return impl_from_IDirect3DSurface8(iface);
385}
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