Replace 10000000 with TICKSPERSEC to make it more obvious what the
[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(d3d);
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         IDirect3DVolume9Impl_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     ULONG ref = InterlockedIncrement(&This->ref);
45
46     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
47
48     return ref;
49 }
50
51 ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
52     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
53     ULONG ref = InterlockedDecrement(&This->ref);
54
55     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
56
57     if (ref == 0) {
58         IWineD3DVolume_Release(This->wineD3DVolume);
59         HeapFree(GetProcessHeap(), 0, This);
60     }
61     return ref;
62 }
63
64 /* IDirect3DVolume9 Interface follow: */
65 HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
66     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
67     IWineD3DDevice       *myDevice = NULL;
68
69     IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
70     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
71     IWineD3DDevice_Release(myDevice);
72     return D3D_OK;
73 }
74
75 HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
76     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
77     return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
78 }
79
80 HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID  refguid, void* pData, DWORD* pSizeOfData) {
81     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
82     return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
83 }
84
85 HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
86     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
87     return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
88 }
89
90 HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
91     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
92     HRESULT res;
93
94     IUnknown *IWineContainer = NULL;
95     res = IWineD3DVolume_GetContainer(This->wineD3DVolume, riid, (void **)&IWineContainer);
96
97     /* If this works, the only valid container is a child of resource (volumetexture) */
98     if (res == D3D_OK && NULL != ppContainer) {
99         IWineD3DResource_GetParent((IWineD3DResource *)IWineContainer, (IUnknown **)ppContainer);
100         IWineD3DResource_Release((IWineD3DResource *)IWineContainer);
101     }
102
103     return res;
104 }
105
106 HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
107     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
108     WINED3DVOLUME_DESC     wined3ddesc;
109     UINT                   tmpInt = -1;
110
111     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
112     wined3ddesc.Format              = &pDesc->Format;
113     wined3ddesc.Type                = &pDesc->Type;
114     wined3ddesc.Usage               = &pDesc->Usage;
115     wined3ddesc.Pool                = &pDesc->Pool;
116     wined3ddesc.Size                = &tmpInt;
117     wined3ddesc.Width               = &pDesc->Width;
118     wined3ddesc.Height              = &pDesc->Height;
119     wined3ddesc.Depth               = &pDesc->Depth;
120
121     return IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
122 }
123
124 HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
125     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
126     return IWineD3DVolume_LockBox(This->wineD3DVolume, pLockedVolume, pBox, Flags);
127 }
128
129 HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
130     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
131     return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
132 }
133
134 IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
135 {
136     IDirect3DVolume9Impl_QueryInterface,
137     IDirect3DVolume9Impl_AddRef,
138     IDirect3DVolume9Impl_Release,
139     IDirect3DVolume9Impl_GetDevice,
140     IDirect3DVolume9Impl_SetPrivateData,
141     IDirect3DVolume9Impl_GetPrivateData,
142     IDirect3DVolume9Impl_FreePrivateData,
143     IDirect3DVolume9Impl_GetContainer,
144     IDirect3DVolume9Impl_GetDesc,
145     IDirect3DVolume9Impl_LockBox,
146     IDirect3DVolume9Impl_UnlockBox
147 };
148
149 /* Internal function called back during the CreateVolumeTexture */
150 HRESULT WINAPI D3D9CB_CreateVolume(IUnknown  *pDevice, UINT Width, UINT Height, UINT Depth, 
151                                    D3DFORMAT  Format, D3DPOOL Pool, DWORD Usage,
152                                    IWineD3DVolume **ppVolume, 
153                                    HANDLE   * pSharedHandle) {
154     IDirect3DVolume9Impl *object;
155     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)pDevice;
156     HRESULT hrc = D3D_OK;
157     
158     /* Allocate the storage for the device */
159     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume9Impl));
160     if (NULL == object) {
161         FIXME("Allocation of memory failed\n");
162         *ppVolume = NULL;
163         return D3DERR_OUTOFVIDEOMEMORY;
164     }
165
166     object->lpVtbl = &Direct3DVolume9_Vtbl;
167     object->ref = 1;
168     hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage, Format, 
169                                        Pool, ppVolume, pSharedHandle, (IUnknown *)object);
170     if (hrc != D3D_OK) {
171         /* free up object */ 
172         FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This);
173         HeapFree(GetProcessHeap(), 0, object);
174         *ppVolume = NULL;
175     } else {
176         *ppVolume = (IWineD3DVolume *)object;
177     }
178     return hrc;
179 }