ws2_32: Rewrite setsockopt to be more readable.
[wine/hacks.git] / dlls / d3d9 / volume.c
blob1575763c1f6b3c89eb92eeeb0b535018c4fd9992
1 /*
2 * IDirect3DVolume9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Raphael Junqueira
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
22 #include "config.h"
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DVolume9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
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 IDirect3DVolume9Impl_AddRef(LPDIRECT3DVOLUME9 iface) {
44 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
45 IUnknown *containerParent = NULL;
47 TRACE("(%p)\n", This);
49 IWineD3DVolume_GetContainerParent(This->wineD3DVolume, &containerParent);
50 if (containerParent) {
51 /* Forward to the containerParent */
52 TRACE("(%p) : Forwarding to %p\n", This, containerParent);
53 return IUnknown_AddRef(containerParent);
54 } else {
55 /* No container, handle our own refcounting */
56 ULONG ref = InterlockedIncrement(&This->ref);
57 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
58 return ref;
62 static ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
63 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
64 IUnknown *containerParent = NULL;
66 TRACE("(%p)\n", This);
68 IWineD3DVolume_GetContainerParent(This->wineD3DVolume, &containerParent);
69 if (containerParent) {
70 /* Forward to the containerParent */
71 TRACE("(%p) : Forwarding to %p\n", This, containerParent);
72 return IUnknown_Release(containerParent);
73 } else {
74 /* No container, handle our own refcounting */
75 ULONG ref = InterlockedDecrement(&This->ref);
76 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
78 if (ref == 0) {
79 IWineD3DVolume_Release(This->wineD3DVolume);
80 HeapFree(GetProcessHeap(), 0, This);
83 return ref;
87 /* IDirect3DVolume9 Interface follow: */
88 static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
89 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
90 IWineD3DDevice *myDevice = NULL;
92 IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
93 IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
94 IWineD3DDevice_Release(myDevice);
95 return D3D_OK;
98 static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
99 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
100 TRACE("(%p) Relay\n", This);
101 return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
104 static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
105 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
106 TRACE("(%p) Relay\n", This);
107 return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
110 static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
111 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
112 TRACE("(%p) Relay\n", This);
113 return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
116 static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
117 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
118 IWineD3DBase *wineD3DContainer = NULL;
119 IUnknown *wineD3DContainerParent = NULL;
120 HRESULT res;
122 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
124 if (!ppContainer) {
125 ERR("Called without a valid ppContainer.\n");
128 /* Get the WineD3D container. */
129 res = IWineD3DVolume_GetContainer(This->wineD3DVolume, &IID_IWineD3DBase, (void **)&wineD3DContainer);
130 if (res != D3D_OK) return res;
132 if (!wineD3DContainer) {
133 ERR("IWineD3DSurface_GetContainer should never return NULL\n");
136 /* Get the parent */
137 IWineD3DBase_GetParent(wineD3DContainer, &wineD3DContainerParent);
138 IUnknown_Release(wineD3DContainer);
140 if (!wineD3DContainerParent) {
141 ERR("IWineD3DBase_GetParent should never return NULL\n");
144 /* Now, query the interface of the parent for the riid */
145 res = IUnknown_QueryInterface(wineD3DContainerParent, riid, ppContainer);
146 IUnknown_Release(wineD3DContainerParent);
148 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
150 return res;
153 static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
154 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
155 WINED3DVOLUME_DESC wined3ddesc;
156 UINT tmpInt = -1;
158 TRACE("(%p) Relay\n", This);
160 /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
161 wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
162 wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
163 wined3ddesc.Usage = &pDesc->Usage;
164 wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
165 wined3ddesc.Size = &tmpInt;
166 wined3ddesc.Width = &pDesc->Width;
167 wined3ddesc.Height = &pDesc->Height;
168 wined3ddesc.Depth = &pDesc->Depth;
170 return IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
173 static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
174 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
175 TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
176 return IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume, (CONST WINED3DBOX *)pBox, Flags);
179 static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
180 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
181 TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
182 return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
185 static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
187 /* IUnknown */
188 IDirect3DVolume9Impl_QueryInterface,
189 IDirect3DVolume9Impl_AddRef,
190 IDirect3DVolume9Impl_Release,
191 /* IDirect3DVolume9 */
192 IDirect3DVolume9Impl_GetDevice,
193 IDirect3DVolume9Impl_SetPrivateData,
194 IDirect3DVolume9Impl_GetPrivateData,
195 IDirect3DVolume9Impl_FreePrivateData,
196 IDirect3DVolume9Impl_GetContainer,
197 IDirect3DVolume9Impl_GetDesc,
198 IDirect3DVolume9Impl_LockBox,
199 IDirect3DVolume9Impl_UnlockBox
203 /* Internal function called back during the CreateVolumeTexture */
204 HRESULT WINAPI D3D9CB_CreateVolume(IUnknown *pDevice, IUnknown *pSuperior, UINT Width, UINT Height, UINT Depth,
205 WINED3DFORMAT Format, WINED3DPOOL Pool, DWORD Usage,
206 IWineD3DVolume **ppVolume,
207 HANDLE * pSharedHandle) {
208 IDirect3DVolume9Impl *object;
209 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)pDevice;
210 HRESULT hrc = D3D_OK;
212 /* Allocate the storage for the device */
213 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume9Impl));
214 if (NULL == object) {
215 FIXME("Allocation of memory failed\n");
216 *ppVolume = NULL;
217 return D3DERR_OUTOFVIDEOMEMORY;
220 object->lpVtbl = &Direct3DVolume9_Vtbl;
221 object->ref = 1;
222 hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage & WINED3DUSAGE_MASK, Format,
223 Pool, &object->wineD3DVolume, pSharedHandle, (IUnknown *)object);
224 if (hrc != D3D_OK) {
225 /* free up object */
226 FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This);
227 HeapFree(GetProcessHeap(), 0, object);
228 *ppVolume = NULL;
229 } else {
230 *ppVolume = (IWineD3DVolume *)object->wineD3DVolume;
232 TRACE("(%p) Created volume %p\n", This, *ppVolume);
233 return hrc;