msdmo: Actually copy output string in IEnumDMO_fnNext.
[wine.git] / dlls / d3d8 / surface.c
blob976894637f3eda2b6bc0603291dae6578a23b5b4
1 /*
2 * IDirect3DSurface8 implementation
4 * Copyright 2005 Oliver Stieber
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.
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.
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
21 #include "config.h"
22 #include "d3d8_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
26 static inline struct d3d8_surface *impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface)
28 return CONTAINING_RECORD(iface, struct d3d8_surface, IDirect3DSurface8_iface);
31 static HRESULT WINAPI d3d8_surface_QueryInterface(IDirect3DSurface8 *iface, REFIID riid, void **out)
33 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), out);
35 if (IsEqualGUID(riid, &IID_IDirect3DSurface8)
36 || IsEqualGUID(riid, &IID_IDirect3DResource8)
37 || IsEqualGUID(riid, &IID_IUnknown))
39 IDirect3DSurface8_AddRef(iface);
40 *out = iface;
41 return S_OK;
44 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
46 *out = NULL;
47 return E_NOINTERFACE;
50 static ULONG WINAPI d3d8_surface_AddRef(IDirect3DSurface8 *iface)
52 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
54 TRACE("iface %p.\n", iface);
56 if (surface->forwardReference)
58 /* Forward refcounting */
59 TRACE("Forwarding to %p.\n", surface->forwardReference);
60 return IUnknown_AddRef(surface->forwardReference);
62 else
64 /* No container, handle our own refcounting */
65 ULONG ref = InterlockedIncrement(&surface->resource.refcount);
67 TRACE("%p increasing refcount to %u.\n", iface, ref);
69 if (ref == 1)
71 if (surface->parent_device)
72 IDirect3DDevice8_AddRef(surface->parent_device);
73 wined3d_mutex_lock();
74 wined3d_surface_incref(surface->wined3d_surface);
75 wined3d_mutex_unlock();
78 return ref;
82 static ULONG WINAPI d3d8_surface_Release(IDirect3DSurface8 *iface)
84 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
86 TRACE("iface %p.\n", iface);
88 if (surface->forwardReference)
90 /* Forward refcounting */
91 TRACE("Forwarding to %p.\n", surface->forwardReference);
92 return IUnknown_Release(surface->forwardReference);
94 else
96 /* No container, handle our own refcounting */
97 ULONG ref = InterlockedDecrement(&surface->resource.refcount);
99 TRACE("%p decreasing refcount to %u.\n", iface, ref);
101 if (!ref)
103 IDirect3DDevice8 *parent_device = surface->parent_device;
105 /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
106 wined3d_mutex_lock();
107 wined3d_surface_decref(surface->wined3d_surface);
108 wined3d_mutex_unlock();
110 if (parent_device)
111 IDirect3DDevice8_Release(parent_device);
114 return ref;
118 static HRESULT WINAPI d3d8_surface_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device)
120 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
122 TRACE("iface %p, device %p.\n", iface, device);
124 if (surface->forwardReference)
126 IDirect3DResource8 *resource;
127 HRESULT hr;
129 hr = IUnknown_QueryInterface(surface->forwardReference, &IID_IDirect3DResource8, (void **)&resource);
130 if (SUCCEEDED(hr))
132 hr = IDirect3DResource8_GetDevice(resource, device);
133 IDirect3DResource8_Release(resource);
135 TRACE("Returning device %p.\n", *device);
138 return hr;
141 *device = surface->parent_device;
142 IDirect3DDevice8_AddRef(*device);
144 TRACE("Returning device %p.\n", *device);
146 return D3D_OK;
149 static HRESULT WINAPI d3d8_surface_SetPrivateData(IDirect3DSurface8 *iface, REFGUID guid,
150 const void *data, DWORD data_size, DWORD flags)
152 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
153 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
154 iface, debugstr_guid(guid), data, data_size, flags);
156 return d3d8_resource_set_private_data(&surface->resource, guid, data, data_size, flags);
159 static HRESULT WINAPI d3d8_surface_GetPrivateData(IDirect3DSurface8 *iface, REFGUID guid,
160 void *data, DWORD *data_size)
162 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
163 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
164 iface, debugstr_guid(guid), data, data_size);
166 return d3d8_resource_get_private_data(&surface->resource, guid, data, data_size);
169 static HRESULT WINAPI d3d8_surface_FreePrivateData(IDirect3DSurface8 *iface, REFGUID guid)
171 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
172 TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
174 return d3d8_resource_free_private_data(&surface->resource, guid);
177 static HRESULT WINAPI d3d8_surface_GetContainer(IDirect3DSurface8 *iface, REFIID riid, void **container)
179 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
180 HRESULT hr;
182 TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), container);
184 if (!surface->container)
185 return E_NOINTERFACE;
187 hr = IUnknown_QueryInterface(surface->container, riid, container);
189 TRACE("Returning %p.\n", *container);
191 return hr;
194 static HRESULT WINAPI d3d8_surface_GetDesc(IDirect3DSurface8 *iface, D3DSURFACE_DESC *desc)
196 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
197 struct wined3d_resource_desc wined3d_desc;
198 struct wined3d_resource *wined3d_resource;
200 TRACE("iface %p, desc %p.\n", iface, desc);
202 wined3d_mutex_lock();
203 wined3d_resource = wined3d_surface_get_resource(surface->wined3d_surface);
204 wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
205 wined3d_mutex_unlock();
207 desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
208 desc->Type = wined3d_desc.resource_type;
209 desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
210 desc->Pool = wined3d_desc.pool;
211 desc->Size = wined3d_desc.size;
212 desc->MultiSampleType = wined3d_desc.multisample_type;
213 desc->Width = wined3d_desc.width;
214 desc->Height = wined3d_desc.height;
216 return D3D_OK;
219 static HRESULT WINAPI d3d8_surface_LockRect(IDirect3DSurface8 *iface,
220 D3DLOCKED_RECT *locked_rect, const RECT *rect, DWORD flags)
222 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
223 struct wined3d_map_desc map_desc;
224 HRESULT hr;
226 TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n",
227 iface, locked_rect, wine_dbgstr_rect(rect), flags);
229 wined3d_mutex_lock();
230 if (rect)
232 D3DSURFACE_DESC desc;
233 IDirect3DSurface8_GetDesc(iface, &desc);
235 if ((rect->left < 0)
236 || (rect->top < 0)
237 || (rect->left >= rect->right)
238 || (rect->top >= rect->bottom)
239 || (rect->right > desc.Width)
240 || (rect->bottom > desc.Height))
242 WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
243 wined3d_mutex_unlock();
245 return D3DERR_INVALIDCALL;
249 hr = wined3d_surface_map(surface->wined3d_surface, &map_desc, rect, flags);
250 wined3d_mutex_unlock();
252 if (SUCCEEDED(hr))
254 locked_rect->Pitch = map_desc.row_pitch;
255 locked_rect->pBits = map_desc.data;
257 else
259 locked_rect->Pitch = 0;
260 locked_rect->pBits = NULL;
263 return hr;
266 static HRESULT WINAPI d3d8_surface_UnlockRect(IDirect3DSurface8 *iface)
268 struct d3d8_surface *surface = impl_from_IDirect3DSurface8(iface);
269 HRESULT hr;
271 TRACE("iface %p.\n", iface);
273 wined3d_mutex_lock();
274 hr = wined3d_surface_unmap(surface->wined3d_surface);
275 wined3d_mutex_unlock();
277 switch(hr)
279 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
280 default: return hr;
284 static const IDirect3DSurface8Vtbl d3d8_surface_vtbl =
286 /* IUnknown */
287 d3d8_surface_QueryInterface,
288 d3d8_surface_AddRef,
289 d3d8_surface_Release,
290 /* IDirect3DResource8 */
291 d3d8_surface_GetDevice,
292 d3d8_surface_SetPrivateData,
293 d3d8_surface_GetPrivateData,
294 d3d8_surface_FreePrivateData,
295 /* IDirect3DSurface8 */
296 d3d8_surface_GetContainer,
297 d3d8_surface_GetDesc,
298 d3d8_surface_LockRect,
299 d3d8_surface_UnlockRect,
302 static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
304 struct d3d8_surface *surface = parent;
305 d3d8_resource_cleanup(&surface->resource);
306 HeapFree(GetProcessHeap(), 0, surface);
309 static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
311 surface_wined3d_object_destroyed,
314 void surface_init(struct d3d8_surface *surface, struct wined3d_surface *wined3d_surface,
315 struct d3d8_device *device, const struct wined3d_parent_ops **parent_ops)
317 surface->IDirect3DSurface8_iface.lpVtbl = &d3d8_surface_vtbl;
318 d3d8_resource_init(&surface->resource);
319 wined3d_surface_incref(wined3d_surface);
320 surface->wined3d_surface = wined3d_surface;
321 surface->parent_device = &device->IDirect3DDevice8_iface;
322 IDirect3DDevice8_AddRef(surface->parent_device);
324 *parent_ops = &d3d8_surface_wined3d_parent_ops;
327 struct d3d8_surface *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface)
329 if (!iface)
330 return NULL;
331 assert(iface->lpVtbl == &d3d8_surface_vtbl);
333 return impl_from_IDirect3DSurface8(iface);