dplayx: Code to parse PlayerEnumeration messages
[wine/gsoc_dplay.git] / dlls / d3d8 / surface.c
blob3185a1f88acd4cc23cffa242b1fc50a3b27d394a
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 /* 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);
34 *ppobj = This;
35 return S_OK;
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39 *ppobj = NULL;
40 return E_NOINTERFACE;
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);
52 } else {
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);
57 return ref;
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);
70 } else {
71 /* No container, handle our own refcounting */
72 ULONG ref = InterlockedDecrement(&This->ref);
73 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
75 if (ref == 0) {
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) {
79 wined3d_mutex_lock();
80 IWineD3DSurface_Release(This->wineD3DSurface);
81 wined3d_mutex_unlock();
83 HeapFree(GetProcessHeap(), 0, This);
87 return ref;
91 /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
92 static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(LPDIRECT3DSURFACE8 iface, IDirect3DDevice8 **ppDevice) {
93 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
94 IWineD3DDevice *wined3d_device;
95 HRESULT hr;
96 TRACE("(%p)->(%p)\n", This, ppDevice);
98 wined3d_mutex_lock();
99 hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
100 if (SUCCEEDED(hr))
102 IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
103 IWineD3DDevice_Release(wined3d_device);
105 wined3d_mutex_unlock();
107 return hr;
110 static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
111 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
112 HRESULT hr;
113 TRACE("(%p) Relay\n", This);
115 wined3d_mutex_lock();
116 hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
117 wined3d_mutex_unlock();
119 return hr;
122 static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
123 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
124 HRESULT hr;
125 TRACE("(%p) Relay\n", This);
127 wined3d_mutex_lock();
128 hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
129 wined3d_mutex_unlock();
131 return hr;
134 static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
135 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
136 HRESULT hr;
137 TRACE("(%p) Relay\n", This);
139 wined3d_mutex_lock();
140 hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
141 wined3d_mutex_unlock();
143 return hr;
146 /* IDirect3DSurface8 Interface follow: */
147 static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) {
148 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
149 HRESULT res;
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);
158 return res;
161 static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(LPDIRECT3DSURFACE8 iface, D3DSURFACE_DESC *pDesc) {
162 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
163 WINED3DSURFACE_DESC wined3ddesc;
164 HRESULT hr;
165 TRACE("(%p) Relay\n", This);
167 wined3d_mutex_lock();
168 hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
169 wined3d_mutex_unlock();
171 if (SUCCEEDED(hr))
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;
183 return hr;
186 static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
187 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
188 HRESULT hr;
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();
193 if (pRect) {
194 D3DSURFACE_DESC desc;
195 IDirect3DSurface8_GetDesc(iface, &desc);
197 if ((pRect->left < 0)
198 || (pRect->top < 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();
213 return hr;
216 static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
217 IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
218 HRESULT hr;
219 TRACE("(%p) Relay\n", This);
221 wined3d_mutex_lock();
222 hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
223 wined3d_mutex_unlock();
225 switch(hr)
227 case WINEDDERR_NOTLOCKED: return D3DERR_INVALIDCALL;
228 default: return hr;
232 const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
234 /* IUnknown */
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