ole32: Register CLSIDs for all OLE monikers.
[wine] / dlls / d3d8 / volume.c
1 /*
2  * IDirect3DVolume8 implementation
3  *
4  * Copyright 2005 Oliver Stieber
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DVolume8 IUnknown parts follow: */
27 HRESULT WINAPI IDirect3DVolume8Impl_QueryInterface(LPDIRECT3DVOLUME8 iface, REFIID riid, LPVOID *ppobj) {
28     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
29
30     if (IsEqualGUID(riid, &IID_IUnknown)
31         || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
32         IUnknown_AddRef(iface);
33         *ppobj = This;
34         return D3D_OK;
35     }
36
37     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
38     return E_NOINTERFACE;
39 }
40
41 ULONG WINAPI IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface) {
42     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
43     IUnknown *containerParent = NULL;
44
45     TRACE("(%p)\n", This);
46
47     IWineD3DVolume_GetContainerParent(This->wineD3DVolume, &containerParent);
48     if (containerParent) {
49         /* Forward to the containerParent */
50         TRACE("(%p) : Forwarding to %p\n", This, containerParent);
51         return IUnknown_AddRef(containerParent);
52     } else {
53         /* No container, handle our own refcounting */
54         ULONG ref = InterlockedIncrement(&This->ref);
55         TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
56         return ref;
57     }
58 }
59
60 ULONG WINAPI IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface) {
61     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
62     IUnknown *containerParent = NULL;
63
64     TRACE("(%p)\n", This);
65
66     IWineD3DVolume_GetContainerParent(This->wineD3DVolume, &containerParent);
67     if (containerParent) {
68         /* Forward to the containerParent */
69         TRACE("(%p) : Forwarding to %p\n", This, containerParent);
70         return IUnknown_Release(containerParent);
71     }
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 /* IDirect3DVolume8 Interface follow: */
87 HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface, IDirect3DDevice8 **ppDevice) {
88     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)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 IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
98     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
99     TRACE("(%p) Relay\n", This);
100     return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
101 }
102
103 HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID  refguid, void *pData, DWORD* pSizeOfData) {
104     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
105     TRACE("(%p) Relay\n", This);
106     return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
107 }
108
109 HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid) {
110     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
111     TRACE("(%p) Relay\n", This);
112     return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
113 }
114
115 HRESULT WINAPI IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface, REFIID riid, void **ppContainer) {
116     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
117     HRESULT res;
118     IUnknown *IWineContainer = NULL;
119
120     TRACE("(%p) Relay\n", This);
121     res = IWineD3DVolume_GetContainer(This->wineD3DVolume, riid, (void **)&IWineContainer);
122
123     /* If this works, the only valid container is a child of resource (volumetexture) */
124     if (res == D3D_OK && NULL != ppContainer) {
125         IWineD3DResource_GetParent((IWineD3DResource *)IWineContainer, (IUnknown **)ppContainer);
126         IWineD3DResource_Release((IWineD3DResource *)IWineContainer);
127     }
128
129     return res;
130 }
131
132 HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface, D3DVOLUME_DESC *pDesc) {
133     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
134     WINED3DVOLUME_DESC     wined3ddesc;
135     UINT                   tmpInt = -1;
136
137     TRACE("(%p) Relay\n", This);
138
139     /* As d3d8 and d3d8 structures differ, pass in ptrs to where data needs to go */
140     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
141     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
142     wined3ddesc.Usage               = &pDesc->Usage;
143     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
144     wined3ddesc.Size                = &tmpInt;
145     wined3ddesc.Width               = &pDesc->Width;
146     wined3ddesc.Height              = &pDesc->Height;
147     wined3ddesc.Depth               = &pDesc->Depth;
148
149     return IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
150 }
151
152 HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox, DWORD Flags) {
153     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
154     TRACE("(%p) relay %p %p %p %ld\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
155     return IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *) pLockedVolume, (WINED3DBOX *) pBox, Flags);
156 }
157
158 HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) {
159     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
160     TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
161     return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
162 }
163
164 const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
165 {
166     /* IUnknown */
167     IDirect3DVolume8Impl_QueryInterface,
168     IDirect3DVolume8Impl_AddRef,
169     IDirect3DVolume8Impl_Release,
170     /* IDirect3DVolume8 */
171     IDirect3DVolume8Impl_GetDevice,
172     IDirect3DVolume8Impl_SetPrivateData,
173     IDirect3DVolume8Impl_GetPrivateData,
174     IDirect3DVolume8Impl_FreePrivateData,
175     IDirect3DVolume8Impl_GetContainer,
176     IDirect3DVolume8Impl_GetDesc,
177     IDirect3DVolume8Impl_LockBox,
178     IDirect3DVolume8Impl_UnlockBox
179 };
180
181
182 /* Internal function called back during the CreateVolumeTexture */
183 HRESULT WINAPI D3D8CB_CreateVolume(IUnknown  *pDevice, UINT Width, UINT Height, UINT Depth, 
184                                    WINED3DFORMAT  Format, WINED3DPOOL Pool, DWORD Usage,
185                                    IWineD3DVolume **ppVolume,
186                                    HANDLE   * pSharedHandle) {
187     IDirect3DVolume8Impl *object;
188     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)pDevice;
189     HRESULT hrc = D3D_OK;
190
191     /* Allocate the storage for the device */
192     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume8Impl));
193     if (NULL == object) {
194         FIXME("Allocation of memory failed\n");
195         *ppVolume = NULL;
196         return D3DERR_OUTOFVIDEOMEMORY;
197     }
198
199     object->lpVtbl = &Direct3DVolume8_Vtbl;
200     object->ref = 1;
201     hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage, Format, 
202                                        Pool, &object->wineD3DVolume, pSharedHandle, (IUnknown *)object);
203     if (hrc != D3D_OK) {
204         /* free up object */ 
205         FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This);
206         HeapFree(GetProcessHeap(), 0, object);
207         *ppVolume = NULL;
208     } else {
209         *ppVolume = (IWineD3DVolume *)object->wineD3DVolume;
210     }
211     TRACE("(%p) Created volume %p\n", This, *ppVolume);
212     return hrc;
213 }