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 /* IDirect3DSurface8 IUnknown parts follow: */
27 static HRESULT WINAPI
IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface
, REFIID riid
, LPVOID
*ppobj
) {
28 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
30 if (IsEqualGUID(riid
, &IID_IUnknown
)
31 || IsEqualGUID(riid
, &IID_IDirect3DResource8
)
32 || IsEqualGUID(riid
, &IID_IDirect3DSurface8
)) {
33 IUnknown_AddRef(iface
);
38 WARN("(%p)->(%s,%p),not found\n", This
, debugstr_guid(riid
), ppobj
);
43 static ULONG WINAPI
IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface
) {
44 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
46 TRACE("(%p)\n", This
);
48 if (This
->forwardReference
) {
49 /* Forward refcounting */
50 TRACE("(%p) : Forwarding to %p\n", This
, This
->forwardReference
);
51 return IUnknown_AddRef(This
->forwardReference
);
53 /* No container, handle our own refcounting */
54 ULONG ref
= InterlockedIncrement(&This
->ref
);
55 if(ref
== 1 && This
->parentDevice
) IUnknown_AddRef(This
->parentDevice
);
56 TRACE("(%p) : AddRef from %d\n", This
, ref
- 1);
61 static ULONG WINAPI
IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface
) {
62 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
64 TRACE("(%p)\n", This
);
66 if (This
->forwardReference
) {
67 /* Forward refcounting */
68 TRACE("(%p) : Forwarding to %p\n", This
, This
->forwardReference
);
69 return IUnknown_Release(This
->forwardReference
);
71 /* No container, handle our own refcounting */
72 ULONG ref
= InterlockedDecrement(&This
->ref
);
73 TRACE("(%p) : ReleaseRef to %d\n", This
, ref
);
76 if (This
->parentDevice
) IUnknown_Release(This
->parentDevice
);
77 /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
78 if (!This
->isImplicit
) {
80 IWineD3DSurface_Release(This
->wineD3DSurface
);
81 wined3d_mutex_unlock();
83 HeapFree(GetProcessHeap(), 0, This
);
91 /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
92 static HRESULT WINAPI
IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface
, IDirect3DDevice8
**ppDevice
) {
93 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
94 IWineD3DDevice
*wined3d_device
;
96 TRACE("(%p)->(%p)\n", This
, ppDevice
);
99 hr
= IWineD3DSurface_GetDevice(This
->wineD3DSurface
, &wined3d_device
);
102 IWineD3DDevice_GetParent(wined3d_device
, (IUnknown
**)ppDevice
);
103 IWineD3DDevice_Release(wined3d_device
);
105 wined3d_mutex_unlock();
110 static HRESULT WINAPI
IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface
, REFGUID refguid
, CONST
void *pData
, DWORD SizeOfData
, DWORD Flags
) {
111 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
113 TRACE("(%p) Relay\n", This
);
115 wined3d_mutex_lock();
116 hr
= IWineD3DSurface_SetPrivateData(This
->wineD3DSurface
, refguid
, pData
, SizeOfData
, Flags
);
117 wined3d_mutex_unlock();
122 static HRESULT WINAPI
IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface
, REFGUID refguid
, void *pData
, DWORD
*pSizeOfData
) {
123 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
125 TRACE("(%p) Relay\n", This
);
127 wined3d_mutex_lock();
128 hr
= IWineD3DSurface_GetPrivateData(This
->wineD3DSurface
, refguid
, pData
, pSizeOfData
);
129 wined3d_mutex_unlock();
134 static HRESULT WINAPI
IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface
, REFGUID refguid
) {
135 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
137 TRACE("(%p) Relay\n", This
);
139 wined3d_mutex_lock();
140 hr
= IWineD3DSurface_FreePrivateData(This
->wineD3DSurface
, refguid
);
141 wined3d_mutex_unlock();
146 /* IDirect3DSurface8 Interface follow: */
147 static HRESULT WINAPI
IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface
, REFIID riid
, void **ppContainer
) {
148 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
151 TRACE("(%p) Relay\n", This
);
153 if (!This
->container
) return E_NOINTERFACE
;
155 res
= IUnknown_QueryInterface(This
->container
, riid
, ppContainer
);
157 TRACE("(%p) : returning %p\n", This
, *ppContainer
);
161 static HRESULT WINAPI
IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface
, D3DSURFACE_DESC
*pDesc
) {
162 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
163 WINED3DSURFACE_DESC wined3ddesc
;
165 TRACE("(%p) Relay\n", This
);
167 wined3d_mutex_lock();
168 hr
= IWineD3DSurface_GetDesc(This
->wineD3DSurface
, &wined3ddesc
);
169 wined3d_mutex_unlock();
173 pDesc
->Format
= d3dformat_from_wined3dformat(wined3ddesc
.format
);
174 pDesc
->Type
= wined3ddesc
.resource_type
;
175 pDesc
->Usage
= wined3ddesc
.usage
;
176 pDesc
->Pool
= wined3ddesc
.pool
;
177 pDesc
->Size
= wined3ddesc
.size
;
178 pDesc
->MultiSampleType
= wined3ddesc
.multisample_type
;
179 pDesc
->Width
= wined3ddesc
.width
;
180 pDesc
->Height
= wined3ddesc
.height
;
186 static HRESULT WINAPI
IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface
, D3DLOCKED_RECT
*pLockedRect
, CONST RECT
*pRect
, DWORD Flags
) {
187 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
189 TRACE("(%p) Relay\n", This
);
190 TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This
, This
->wineD3DSurface
, pLockedRect
, pRect
, Flags
);
192 wined3d_mutex_lock();
194 D3DSURFACE_DESC desc
;
195 IDirect3DSurface8_GetDesc(iface
, &desc
);
197 if ((pRect
->left
< 0)
199 || (pRect
->left
>= pRect
->right
)
200 || (pRect
->top
>= pRect
->bottom
)
201 || (pRect
->right
> desc
.Width
)
202 || (pRect
->bottom
> desc
.Height
)) {
203 WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
204 wined3d_mutex_unlock();
206 return D3DERR_INVALIDCALL
;
210 hr
= IWineD3DSurface_LockRect(This
->wineD3DSurface
, (WINED3DLOCKED_RECT
*) pLockedRect
, pRect
, Flags
);
211 wined3d_mutex_unlock();
216 static HRESULT WINAPI
IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface
) {
217 IDirect3DSurface8Impl
*This
= (IDirect3DSurface8Impl
*)iface
;
219 TRACE("(%p) Relay\n", This
);
221 wined3d_mutex_lock();
222 hr
= IWineD3DSurface_UnlockRect(This
->wineD3DSurface
);
223 wined3d_mutex_unlock();
227 case WINEDDERR_NOTLOCKED
: return D3DERR_INVALIDCALL
;
232 const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl
=
235 IDirect3DSurface8Impl_QueryInterface
,
236 IDirect3DSurface8Impl_AddRef
,
237 IDirect3DSurface8Impl_Release
,
238 /* IDirect3DResource8 */
239 IDirect3DSurface8Impl_GetDevice
,
240 IDirect3DSurface8Impl_SetPrivateData
,
241 IDirect3DSurface8Impl_GetPrivateData
,
242 IDirect3DSurface8Impl_FreePrivateData
,
243 /* IDirect3DSurface8 */
244 IDirect3DSurface8Impl_GetContainer
,
245 IDirect3DSurface8Impl_GetDesc
,
246 IDirect3DSurface8Impl_LockRect
,
247 IDirect3DSurface8Impl_UnlockRect