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
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
);
44 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
50 static ULONG WINAPI
d3d8_surface_AddRef(IDirect3DSurface8
*iface
)
52 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
55 TRACE("iface %p.\n", iface
);
59 TRACE("Forwarding to %p.\n", surface
->texture
);
60 return IDirect3DBaseTexture8_AddRef(&surface
->texture
->IDirect3DBaseTexture8_iface
);
63 refcount
= InterlockedIncrement(&surface
->resource
.refcount
);
64 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
68 if (surface
->parent_device
)
69 IDirect3DDevice8_AddRef(surface
->parent_device
);
71 wined3d_surface_incref(surface
->wined3d_surface
);
72 wined3d_mutex_unlock();
78 static ULONG WINAPI
d3d8_surface_Release(IDirect3DSurface8
*iface
)
80 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
83 TRACE("iface %p.\n", iface
);
87 TRACE("Forwarding to %p.\n", surface
->texture
);
88 return IDirect3DBaseTexture8_Release(&surface
->texture
->IDirect3DBaseTexture8_iface
);
91 refcount
= InterlockedDecrement(&surface
->resource
.refcount
);
92 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
96 IDirect3DDevice8
*parent_device
= surface
->parent_device
;
99 wined3d_surface_decref(surface
->wined3d_surface
);
100 wined3d_mutex_unlock();
103 IDirect3DDevice8_Release(parent_device
);
109 static HRESULT WINAPI
d3d8_surface_GetDevice(IDirect3DSurface8
*iface
, IDirect3DDevice8
**device
)
111 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
113 TRACE("iface %p, device %p.\n", iface
, device
);
115 if (surface
->texture
)
116 return IDirect3DBaseTexture8_GetDevice(&surface
->texture
->IDirect3DBaseTexture8_iface
, device
);
118 *device
= surface
->parent_device
;
119 IDirect3DDevice8_AddRef(*device
);
121 TRACE("Returning device %p.\n", *device
);
126 static HRESULT WINAPI
d3d8_surface_SetPrivateData(IDirect3DSurface8
*iface
, REFGUID guid
,
127 const void *data
, DWORD data_size
, DWORD flags
)
129 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
130 TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
131 iface
, debugstr_guid(guid
), data
, data_size
, flags
);
133 return d3d8_resource_set_private_data(&surface
->resource
, guid
, data
, data_size
, flags
);
136 static HRESULT WINAPI
d3d8_surface_GetPrivateData(IDirect3DSurface8
*iface
, REFGUID guid
,
137 void *data
, DWORD
*data_size
)
139 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
140 TRACE("iface %p, guid %s, data %p, data_size %p.\n",
141 iface
, debugstr_guid(guid
), data
, data_size
);
143 return d3d8_resource_get_private_data(&surface
->resource
, guid
, data
, data_size
);
146 static HRESULT WINAPI
d3d8_surface_FreePrivateData(IDirect3DSurface8
*iface
, REFGUID guid
)
148 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
149 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
151 return d3d8_resource_free_private_data(&surface
->resource
, guid
);
154 static HRESULT WINAPI
d3d8_surface_GetContainer(IDirect3DSurface8
*iface
, REFIID riid
, void **container
)
156 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
159 TRACE("iface %p, riid %s, container %p.\n", iface
, debugstr_guid(riid
), container
);
161 if (!surface
->container
)
162 return E_NOINTERFACE
;
164 hr
= IUnknown_QueryInterface(surface
->container
, riid
, container
);
166 TRACE("Returning %p.\n", *container
);
171 static HRESULT WINAPI
d3d8_surface_GetDesc(IDirect3DSurface8
*iface
, D3DSURFACE_DESC
*desc
)
173 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
174 struct wined3d_resource_desc wined3d_desc
;
175 struct wined3d_resource
*wined3d_resource
;
177 TRACE("iface %p, desc %p.\n", iface
, desc
);
179 wined3d_mutex_lock();
180 wined3d_resource
= wined3d_surface_get_resource(surface
->wined3d_surface
);
181 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
182 wined3d_mutex_unlock();
184 desc
->Format
= d3dformat_from_wined3dformat(wined3d_desc
.format
);
185 desc
->Type
= wined3d_desc
.resource_type
;
186 desc
->Usage
= wined3d_desc
.usage
& WINED3DUSAGE_MASK
;
187 desc
->Pool
= wined3d_desc
.pool
;
188 desc
->Size
= wined3d_desc
.size
;
189 desc
->MultiSampleType
= wined3d_desc
.multisample_type
;
190 desc
->Width
= wined3d_desc
.width
;
191 desc
->Height
= wined3d_desc
.height
;
196 static HRESULT WINAPI
d3d8_surface_LockRect(IDirect3DSurface8
*iface
,
197 D3DLOCKED_RECT
*locked_rect
, const RECT
*rect
, DWORD flags
)
199 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
200 struct wined3d_map_desc map_desc
;
203 TRACE("iface %p, locked_rect %p, rect %s, flags %#x.\n",
204 iface
, locked_rect
, wine_dbgstr_rect(rect
), flags
);
206 wined3d_mutex_lock();
209 D3DSURFACE_DESC desc
;
210 IDirect3DSurface8_GetDesc(iface
, &desc
);
214 || (rect
->left
>= rect
->right
)
215 || (rect
->top
>= rect
->bottom
)
216 || (rect
->right
> desc
.Width
)
217 || (rect
->bottom
> desc
.Height
))
219 WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
220 wined3d_mutex_unlock();
222 return D3DERR_INVALIDCALL
;
226 hr
= wined3d_surface_map(surface
->wined3d_surface
, &map_desc
, rect
, flags
);
227 wined3d_mutex_unlock();
231 locked_rect
->Pitch
= map_desc
.row_pitch
;
232 locked_rect
->pBits
= map_desc
.data
;
236 locked_rect
->Pitch
= 0;
237 locked_rect
->pBits
= NULL
;
243 static HRESULT WINAPI
d3d8_surface_UnlockRect(IDirect3DSurface8
*iface
)
245 struct d3d8_surface
*surface
= impl_from_IDirect3DSurface8(iface
);
248 TRACE("iface %p.\n", iface
);
250 wined3d_mutex_lock();
251 hr
= wined3d_surface_unmap(surface
->wined3d_surface
);
252 wined3d_mutex_unlock();
256 case WINEDDERR_NOTLOCKED
: return D3DERR_INVALIDCALL
;
261 static const IDirect3DSurface8Vtbl d3d8_surface_vtbl
=
264 d3d8_surface_QueryInterface
,
266 d3d8_surface_Release
,
267 /* IDirect3DResource8 */
268 d3d8_surface_GetDevice
,
269 d3d8_surface_SetPrivateData
,
270 d3d8_surface_GetPrivateData
,
271 d3d8_surface_FreePrivateData
,
272 /* IDirect3DSurface8 */
273 d3d8_surface_GetContainer
,
274 d3d8_surface_GetDesc
,
275 d3d8_surface_LockRect
,
276 d3d8_surface_UnlockRect
,
279 static void STDMETHODCALLTYPE
surface_wined3d_object_destroyed(void *parent
)
281 struct d3d8_surface
*surface
= parent
;
282 d3d8_resource_cleanup(&surface
->resource
);
283 HeapFree(GetProcessHeap(), 0, surface
);
286 static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops
=
288 surface_wined3d_object_destroyed
,
291 void surface_init(struct d3d8_surface
*surface
, IUnknown
*container_parent
,
292 struct wined3d_surface
*wined3d_surface
, const struct wined3d_parent_ops
**parent_ops
)
294 IDirect3DBaseTexture8
*texture
;
296 surface
->IDirect3DSurface8_iface
.lpVtbl
= &d3d8_surface_vtbl
;
297 d3d8_resource_init(&surface
->resource
);
298 surface
->resource
.refcount
= 0;
299 surface
->wined3d_surface
= wined3d_surface
;
300 surface
->container
= container_parent
;
302 if (container_parent
&& SUCCEEDED(IUnknown_QueryInterface(container_parent
,
303 &IID_IDirect3DBaseTexture8
, (void **)&texture
)))
305 surface
->texture
= unsafe_impl_from_IDirect3DBaseTexture8(texture
);
306 IDirect3DBaseTexture8_Release(texture
);
309 *parent_ops
= &d3d8_surface_wined3d_parent_ops
;
312 struct d3d8_surface
*unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8
*iface
)
316 assert(iface
->lpVtbl
== &d3d8_surface_vtbl
);
318 return impl_from_IDirect3DSurface8(iface
);