comctl32: A couple fixes for tab icon offsets.
[wine] / dlls / d3d9 / volume.c
1 /*
2  * IDirect3DVolume9 implementation
3  *
4  * Copyright 2002-2005 Jason Edmeades
5  *                     Raphael Junqueira
6  *
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.
11  *
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.
16  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
26
27 /* IDirect3DVolume9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
33         IUnknown_AddRef(iface);
34         *ppobj = This;
35         return D3D_OK;
36     }
37
38     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39     return E_NOINTERFACE;
40 }
41
42 ULONG WINAPI IDirect3DVolume9Impl_AddRef(LPDIRECT3DVOLUME9 iface) {
43     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
44     IUnknown *containerParent = NULL;
45
46     TRACE("(%p)\n", This);
47
48     IWineD3DVolume_GetContainerParent(This->wineD3DVolume, &containerParent);
49     if (containerParent) {
50         /* Forward to the containerParent */
51         TRACE("(%p) : Forwarding to %p\n", This, containerParent);
52         return IUnknown_AddRef(containerParent);
53     } else {
54         /* No container, handle our own refcounting */
55         ULONG ref = InterlockedIncrement(&This->ref);
56         TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
57         return ref;
58     }
59 }
60
61 ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
62     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
63     IUnknown *containerParent = NULL;
64
65     TRACE("(%p)\n", This);
66
67     IWineD3DVolume_GetContainerParent(This->wineD3DVolume, &containerParent);
68     if (containerParent) {
69         /* Forward to the containerParent */
70         TRACE("(%p) : Forwarding to %p\n", This, containerParent);
71         return IUnknown_Release(containerParent);
72     } else {
73         /* No container, handle our own refcounting */
74         ULONG ref = InterlockedDecrement(&This->ref);
75         TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
76
77         if (ref == 0) {
78             IWineD3DVolume_Release(This->wineD3DVolume);
79             HeapFree(GetProcessHeap(), 0, This);
80         }
81
82         return ref;
83     }
84 }
85
86 /* IDirect3DVolume9 Interface follow: */
87 HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
88     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
89     IWineD3DDevice       *myDevice = NULL;
90
91     IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
92     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
93     IWineD3DDevice_Release(myDevice);
94     return D3D_OK;
95 }
96
97 HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
98     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
99     TRACE("(%p) Relay\n", This);
100     return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
101 }
102
103 HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID  refguid, void* pData, DWORD* pSizeOfData) {
104     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
105     TRACE("(%p) Relay\n", This);
106     return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
107 }
108
109 HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
110     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
111     TRACE("(%p) Relay\n", This);
112     return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
113 }
114
115 HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
116     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
117     IWineD3DBase *wineD3DContainer = NULL;
118     IUnknown *wineD3DContainerParent = NULL;
119     HRESULT res;
120
121     TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
122
123     if (!ppContainer) {
124         ERR("Called without a valid ppContainer.\n");
125     }
126
127     /* Get the WineD3D container. */
128     res = IWineD3DVolume_GetContainer(This->wineD3DVolume, &IID_IWineD3DBase, (void **)&wineD3DContainer);
129     if (res != D3D_OK) return res;
130
131     if (!wineD3DContainer) {
132         ERR("IWineD3DSurface_GetContainer should never return NULL\n");
133     }
134
135     /* Get the parent */
136     IWineD3DBase_GetParent(wineD3DContainer, &wineD3DContainerParent);
137     IUnknown_Release(wineD3DContainer);
138
139     if (!wineD3DContainerParent) {
140         ERR("IWineD3DBase_GetParent should never return NULL\n");
141     }
142
143     /* Now, query the interface of the parent for the riid */
144     res = IUnknown_QueryInterface(wineD3DContainerParent, riid, ppContainer);
145     IUnknown_Release(wineD3DContainerParent);
146
147     TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
148
149     return res;
150 }
151
152 HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
153     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
154     WINED3DVOLUME_DESC     wined3ddesc;
155     UINT                   tmpInt = -1;
156
157     TRACE("(%p) Relay\n", This);
158
159     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
160     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
161     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
162     wined3ddesc.Usage               = &pDesc->Usage;
163     wined3ddesc.Pool                = &pDesc->Pool;
164     wined3ddesc.Size                = &tmpInt;
165     wined3ddesc.Width               = &pDesc->Width;
166     wined3ddesc.Height              = &pDesc->Height;
167     wined3ddesc.Depth               = &pDesc->Depth;
168
169     return IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
170 }
171
172 HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
173     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
174     TRACE("(%p) relay %p %p %p %ld\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
175     return IWineD3DVolume_LockBox(This->wineD3DVolume, pLockedVolume, pBox, Flags);
176 }
177
178 HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
179     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
180     TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
181     return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
182 }
183
184 const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
185 {
186     /* IUnknown */
187     IDirect3DVolume9Impl_QueryInterface,
188     IDirect3DVolume9Impl_AddRef,
189     IDirect3DVolume9Impl_Release,
190     /* IDirect3DVolume9 */
191     IDirect3DVolume9Impl_GetDevice,
192     IDirect3DVolume9Impl_SetPrivateData,
193     IDirect3DVolume9Impl_GetPrivateData,
194     IDirect3DVolume9Impl_FreePrivateData,
195     IDirect3DVolume9Impl_GetContainer,
196     IDirect3DVolume9Impl_GetDesc,
197     IDirect3DVolume9Impl_LockBox,
198     IDirect3DVolume9Impl_UnlockBox
199 };
200
201
202 /* Internal function called back during the CreateVolumeTexture */
203 HRESULT WINAPI D3D9CB_CreateVolume(IUnknown  *pDevice, UINT Width, UINT Height, UINT Depth, 
204                                    WINED3DFORMAT  Format, D3DPOOL Pool, DWORD Usage,
205                                    IWineD3DVolume **ppVolume, 
206                                    HANDLE   * pSharedHandle) {
207     IDirect3DVolume9Impl *object;
208     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)pDevice;
209     HRESULT hrc = D3D_OK;
210     
211     /* Allocate the storage for the device */
212     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume9Impl));
213     if (NULL == object) {
214         FIXME("Allocation of memory failed\n");
215         *ppVolume = NULL;
216         return D3DERR_OUTOFVIDEOMEMORY;
217     }
218
219     object->lpVtbl = &Direct3DVolume9_Vtbl;
220     object->ref = 1;
221     hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage, Format, 
222                                        Pool, &object->wineD3DVolume, pSharedHandle, (IUnknown *)object);
223     if (hrc != D3D_OK) {
224         /* free up object */ 
225         FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This);
226         HeapFree(GetProcessHeap(), 0, object);
227         *ppVolume = NULL;
228     } else {
229         *ppVolume = (IWineD3DVolume *)object->wineD3DVolume;
230     }
231     TRACE("(%p) Created volume %p\n", This, *ppVolume);
232     return hrc;
233 }