2 * IDirect3DSurface9 implementation
4 * Copyright 2002-2005 Jason Edmeades
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
27 /* IDirect3DSurface9 IUnknown parts follow: */
28 static HRESULT WINAPI
IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface
, REFIID riid
, LPVOID
* ppobj
) {
29 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
31 if (IsEqualGUID(riid
, &IID_IUnknown
)
32 || IsEqualGUID(riid
, &IID_IDirect3DResource9
)
33 || IsEqualGUID(riid
, &IID_IDirect3DSurface9
)) {
34 IDirect3DSurface9_AddRef(iface
);
39 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
44 static ULONG WINAPI
IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface
) {
45 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
47 TRACE("(%p)\n", This
);
49 if (This
->forwardReference
) {
50 /* Forward refcounting */
51 TRACE("(%p) : Forwarding to %p\n", This
, This
->forwardReference
);
52 return IUnknown_AddRef(This
->forwardReference
);
54 /* No container, handle our own refcounting */
55 ULONG ref
= InterlockedIncrement(&This
->ref
);
58 if (This
->parentDevice
) IDirect3DDevice9Ex_AddRef(This
->parentDevice
);
60 IWineD3DSurface_AddRef(This
->wineD3DSurface
);
61 wined3d_mutex_unlock();
63 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
70 static ULONG WINAPI
IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface
) {
71 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
73 TRACE("(%p)\n", This
);
75 if (This
->forwardReference
) {
76 /* Forward to the containerParent */
77 TRACE("(%p) : Forwarding to %p\n", This
, This
->forwardReference
);
78 return IUnknown_Release(This
->forwardReference
);
80 /* No container, handle our own refcounting */
81 ULONG ref
= InterlockedDecrement(&This
->ref
);
82 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
85 if (This
->parentDevice
) IDirect3DDevice9Ex_Release(This
->parentDevice
);
87 IWineD3DSurface_Release(This
->wineD3DSurface
);
88 wined3d_mutex_unlock();
95 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
96 static HRESULT WINAPI
IDirect3DSurface9Impl_GetDevice(LPDIRECT3DSURFACE9 iface
, IDirect3DDevice9
** ppDevice
) {
97 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
98 IWineD3DDevice
*wined3d_device
;
100 TRACE("(%p)->(%p)\n", This
, ppDevice
);
102 wined3d_mutex_lock();
103 hr
= IWineD3DSurface_GetDevice(This
->wineD3DSurface
, &wined3d_device
);
106 IWineD3DDevice_GetParent(wined3d_device
, (IUnknown
**)ppDevice
);
107 IWineD3DDevice_Release(wined3d_device
);
109 wined3d_mutex_unlock();
114 static HRESULT WINAPI
IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface
, REFGUID refguid
, CONST
void* pData
, DWORD SizeOfData
, DWORD Flags
) {
115 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
117 TRACE("(%p) Relay\n", This
);
119 wined3d_mutex_lock();
120 hr
= IWineD3DSurface_SetPrivateData(This
->wineD3DSurface
, refguid
, pData
, SizeOfData
, Flags
);
121 wined3d_mutex_unlock();
126 static HRESULT WINAPI
IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface
, REFGUID refguid
, void* pData
, DWORD
* pSizeOfData
) {
127 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
129 TRACE("(%p) Relay\n", This
);
131 wined3d_mutex_lock();
132 hr
= IWineD3DSurface_GetPrivateData(This
->wineD3DSurface
, refguid
, pData
, pSizeOfData
);
133 wined3d_mutex_unlock();
138 static HRESULT WINAPI
IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface
, REFGUID refguid
) {
139 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
141 TRACE("(%p) Relay\n", This
);
143 wined3d_mutex_lock();
144 hr
= IWineD3DSurface_FreePrivateData(This
->wineD3DSurface
, refguid
);
145 wined3d_mutex_unlock();
150 static DWORD WINAPI
IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface
, DWORD PriorityNew
) {
151 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
153 TRACE("(%p) Relay\n", This
);
155 wined3d_mutex_lock();
156 hr
= IWineD3DSurface_SetPriority(This
->wineD3DSurface
, PriorityNew
);
157 wined3d_mutex_unlock();
162 static DWORD WINAPI
IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface
) {
163 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
165 TRACE("(%p) Relay\n", This
);
167 wined3d_mutex_lock();
168 hr
= IWineD3DSurface_GetPriority(This
->wineD3DSurface
);
169 wined3d_mutex_unlock();
174 static void WINAPI
IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface
) {
175 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
176 TRACE("(%p) Relay\n", This
);
178 wined3d_mutex_lock();
179 IWineD3DSurface_PreLoad(This
->wineD3DSurface
);
180 wined3d_mutex_unlock();
183 static D3DRESOURCETYPE WINAPI
IDirect3DSurface9Impl_GetType(LPDIRECT3DSURFACE9 iface
) {
184 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
186 TRACE("(%p) Relay\n", This
);
188 wined3d_mutex_lock();
189 ret
= IWineD3DSurface_GetType(This
->wineD3DSurface
);
190 wined3d_mutex_unlock();
195 /* IDirect3DSurface9 Interface follow: */
196 static HRESULT WINAPI
IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface
, REFIID riid
, void** ppContainer
) {
197 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
200 TRACE("(This %p, riid %s, ppContainer %p)\n", This
, debugstr_guid(riid
), ppContainer
);
202 if (!This
->container
) return E_NOINTERFACE
;
205 ERR("Called without a valid ppContainer\n");
208 res
= IUnknown_QueryInterface(This
->container
, riid
, ppContainer
);
210 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer
, *ppContainer
);
215 static HRESULT WINAPI
IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface
, D3DSURFACE_DESC
* pDesc
) {
216 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
217 WINED3DSURFACE_DESC wined3ddesc
;
219 TRACE("(%p) Relay\n", This
);
221 wined3d_mutex_lock();
222 hr
= IWineD3DSurface_GetDesc(This
->wineD3DSurface
, &wined3ddesc
);
223 wined3d_mutex_unlock();
227 pDesc
->Format
= d3dformat_from_wined3dformat(wined3ddesc
.format
);
228 pDesc
->Type
= wined3ddesc
.resource_type
;
229 pDesc
->Usage
= wined3ddesc
.usage
;
230 pDesc
->Pool
= wined3ddesc
.pool
;
231 pDesc
->MultiSampleType
= wined3ddesc
.multisample_type
;
232 pDesc
->MultiSampleQuality
= wined3ddesc
.multisample_quality
;
233 pDesc
->Width
= wined3ddesc
.width
;
234 pDesc
->Height
= wined3ddesc
.height
;
240 static HRESULT WINAPI
IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface
, D3DLOCKED_RECT
* pLockedRect
, CONST RECT
* pRect
, DWORD Flags
) {
241 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
243 TRACE("(%p) Relay\n", This
);
245 wined3d_mutex_lock();
246 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This
, This
->wineD3DSurface
, pLockedRect
, pRect
, Flags
);
247 hr
= IWineD3DSurface_LockRect(This
->wineD3DSurface
, (WINED3DLOCKED_RECT
*) pLockedRect
, pRect
, Flags
);
248 wined3d_mutex_unlock();
253 static HRESULT WINAPI
IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface
) {
254 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
256 TRACE("(%p) Relay\n", This
);
258 wined3d_mutex_lock();
259 hr
= IWineD3DSurface_UnlockRect(This
->wineD3DSurface
);
260 wined3d_mutex_unlock();
264 case WINEDDERR_NOTLOCKED
: return D3DERR_INVALIDCALL
;
269 static HRESULT WINAPI
IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface
, HDC
* phdc
) {
270 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
272 TRACE("(%p) Relay\n", This
);
274 if(!This
->getdc_supported
)
276 WARN("Surface does not support GetDC, returning D3DERR_INVALIDCALL\n");
277 /* Don't touch the DC */
278 return D3DERR_INVALIDCALL
;
281 wined3d_mutex_lock();
282 hr
= IWineD3DSurface_GetDC(This
->wineD3DSurface
, phdc
);
283 wined3d_mutex_unlock();
288 static HRESULT WINAPI
IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface
, HDC hdc
) {
289 IDirect3DSurface9Impl
*This
= (IDirect3DSurface9Impl
*)iface
;
291 TRACE("(%p) Relay\n", This
);
293 wined3d_mutex_lock();
294 hr
= IWineD3DSurface_ReleaseDC(This
->wineD3DSurface
, hdc
);
295 wined3d_mutex_unlock();
298 case WINEDDERR_NODC
: return WINED3DERR_INVALIDCALL
;
303 static const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl
=
306 IDirect3DSurface9Impl_QueryInterface
,
307 IDirect3DSurface9Impl_AddRef
,
308 IDirect3DSurface9Impl_Release
,
309 /* IDirect3DResource9 */
310 IDirect3DSurface9Impl_GetDevice
,
311 IDirect3DSurface9Impl_SetPrivateData
,
312 IDirect3DSurface9Impl_GetPrivateData
,
313 IDirect3DSurface9Impl_FreePrivateData
,
314 IDirect3DSurface9Impl_SetPriority
,
315 IDirect3DSurface9Impl_GetPriority
,
316 IDirect3DSurface9Impl_PreLoad
,
317 IDirect3DSurface9Impl_GetType
,
318 /* IDirect3DSurface9 */
319 IDirect3DSurface9Impl_GetContainer
,
320 IDirect3DSurface9Impl_GetDesc
,
321 IDirect3DSurface9Impl_LockRect
,
322 IDirect3DSurface9Impl_UnlockRect
,
323 IDirect3DSurface9Impl_GetDC
,
324 IDirect3DSurface9Impl_ReleaseDC
327 static void STDMETHODCALLTYPE
surface_wined3d_object_destroyed(void *parent
)
329 HeapFree(GetProcessHeap(), 0, parent
);
332 static const struct wined3d_parent_ops d3d9_surface_wined3d_parent_ops
=
334 surface_wined3d_object_destroyed
,
337 HRESULT
surface_init(IDirect3DSurface9Impl
*surface
, IDirect3DDevice9Impl
*device
,
338 UINT width
, UINT height
, D3DFORMAT format
, BOOL lockable
, BOOL discard
, UINT level
,
339 DWORD usage
, D3DPOOL pool
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
)
343 surface
->lpVtbl
= &Direct3DSurface9_Vtbl
;
348 case D3DFMT_A8R8G8B8
:
349 case D3DFMT_X8R8G8B8
:
351 case D3DFMT_X1R5G5B5
:
352 case D3DFMT_A1R5G5B5
:
354 surface
->getdc_supported
= TRUE
;
358 surface
->getdc_supported
= FALSE
;
362 /* FIXME: Check MAX bounds of MultisampleQuality. */
363 if (multisample_quality
> 0)
365 FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality
);
366 multisample_quality
= 0;
369 wined3d_mutex_lock();
370 hr
= IWineD3DDevice_CreateSurface(device
->WineD3DDevice
, width
, height
, wined3dformat_from_d3dformat(format
),
371 lockable
, discard
, level
, &surface
->wineD3DSurface
, usage
& WINED3DUSAGE_MASK
, (WINED3DPOOL
)pool
,
372 multisample_type
, multisample_quality
, SURFACE_OPENGL
, (IUnknown
*)surface
,
373 &d3d9_surface_wined3d_parent_ops
);
374 wined3d_mutex_unlock();
377 WARN("Failed to create wined3d surface, hr %#x.\n", hr
);
381 surface
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
382 IDirect3DDevice9Ex_AddRef(surface
->parentDevice
);