kernel32: GetTimeFormat and GetDateFormat should fail if LOCALE_NOUSEROVERRIDE is...
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 static 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 S_OK;
35     }
36
37     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
38     *ppobj = NULL;
39     return E_NOINTERFACE;
40 }
41
42 static ULONG WINAPI IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface) {
43     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
44
45     TRACE("(%p)\n", This);
46
47     if (This->forwardReference) {
48         /* Forward to the containerParent */
49         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
50         return IUnknown_AddRef(This->forwardReference);
51     } else {
52         /* No container, handle our own refcounting */
53         ULONG ref = InterlockedIncrement(&This->ref);
54         TRACE("(%p) : AddRef from %d\n", This, ref - 1);
55         return ref;
56     }
57 }
58
59 static ULONG WINAPI IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface) {
60     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
61
62     TRACE("(%p)\n", This);
63
64     if (This->forwardReference) {
65         /* Forward to the containerParent */
66         TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
67         return IUnknown_Release(This->forwardReference);
68     }
69     else {
70         /* No container, handle our own refcounting */
71         ULONG ref = InterlockedDecrement(&This->ref);
72         TRACE("(%p) : ReleaseRef to %d\n", This, ref);
73
74         if (ref == 0) {
75             IWineD3DVolume_Release(This->wineD3DVolume);
76             HeapFree(GetProcessHeap(), 0, This);
77         }
78
79         return ref;
80     }
81 }
82
83 /* IDirect3DVolume8 Interface follow: */
84 static HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface, IDirect3DDevice8 **ppDevice) {
85     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
86     IWineD3DDevice       *myDevice = NULL;
87
88     IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
89     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
90     IWineD3DDevice_Release(myDevice);
91     return D3D_OK;
92 }
93
94 static HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
95     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
96     TRACE("(%p) Relay\n", This);
97     return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
98 }
99
100 static HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID  refguid, void *pData, DWORD* pSizeOfData) {
101     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
102     TRACE("(%p) Relay\n", This);
103     return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
104 }
105
106 static HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid) {
107     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
108     TRACE("(%p) Relay\n", This);
109     return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
110 }
111
112 static HRESULT WINAPI IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface, REFIID riid, void **ppContainer) {
113     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
114     HRESULT res;
115
116     TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
117
118     if (!This->container) return E_NOINTERFACE;
119
120     if (!ppContainer) {
121         ERR("Called without a valid ppContainer.\n");
122     }
123
124     res = IUnknown_QueryInterface(This->container, riid, ppContainer);
125
126     TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
127
128     return res;
129 }
130
131 static HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface, D3DVOLUME_DESC *pDesc) {
132     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
133     WINED3DVOLUME_DESC     wined3ddesc;
134
135     TRACE("(%p) Relay\n", This);
136
137     /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
138     wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
139     wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
140     wined3ddesc.Usage               = &pDesc->Usage;
141     wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
142     wined3ddesc.Size                = &pDesc->Size;
143     wined3ddesc.Width               = &pDesc->Width;
144     wined3ddesc.Height              = &pDesc->Height;
145     wined3ddesc.Depth               = &pDesc->Depth;
146
147     return IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
148 }
149
150 static HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX *pLockedVolume, CONST D3DBOX *pBox, DWORD Flags) {
151     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
152     TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
153     return IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
154 }
155
156 static HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) {
157     IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
158     TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
159     return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
160 }
161
162 static const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
163 {
164     /* IUnknown */
165     IDirect3DVolume8Impl_QueryInterface,
166     IDirect3DVolume8Impl_AddRef,
167     IDirect3DVolume8Impl_Release,
168     /* IDirect3DVolume8 */
169     IDirect3DVolume8Impl_GetDevice,
170     IDirect3DVolume8Impl_SetPrivateData,
171     IDirect3DVolume8Impl_GetPrivateData,
172     IDirect3DVolume8Impl_FreePrivateData,
173     IDirect3DVolume8Impl_GetContainer,
174     IDirect3DVolume8Impl_GetDesc,
175     IDirect3DVolume8Impl_LockBox,
176     IDirect3DVolume8Impl_UnlockBox
177 };
178
179
180 /* Internal function called back during the CreateVolumeTexture */
181 HRESULT WINAPI D3D8CB_CreateVolume(IUnknown  *pDevice, IUnknown *pSuperior, UINT Width, UINT Height, UINT Depth,
182                                    WINED3DFORMAT  Format, WINED3DPOOL Pool, DWORD Usage,
183                                    IWineD3DVolume **ppVolume,
184                                    HANDLE   * pSharedHandle) {
185     IDirect3DVolume8Impl *object;
186     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)pDevice;
187     HRESULT hrc = D3D_OK;
188
189     /* Allocate the storage for the device */
190     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume8Impl));
191     if (NULL == object) {
192         FIXME("Allocation of memory failed\n");
193         *ppVolume = NULL;
194         return D3DERR_OUTOFVIDEOMEMORY;
195     }
196
197     object->lpVtbl = &Direct3DVolume8_Vtbl;
198     object->ref = 1;
199     hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage, Format, 
200                                        Pool, &object->wineD3DVolume, pSharedHandle, (IUnknown *)object);
201     if (hrc != D3D_OK) {
202         /* free up object */ 
203         FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This);
204         HeapFree(GetProcessHeap(), 0, object);
205         *ppVolume = NULL;
206     } else {
207         *ppVolume = (IWineD3DVolume *)object->wineD3DVolume;
208         object->container = pSuperior;
209         object->forwardReference = pSuperior;
210     }
211     TRACE("(%p) Created volume %p\n", This, *ppVolume);
212     return hrc;
213 }
214
215 ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume) {
216     IDirect3DVolume8Impl* volumeParent;
217
218     IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
219     /* GetParent's AddRef was forwarded to an object in destruction.
220      * Releasing it here again would cause an endless recursion. */
221     volumeParent->forwardReference = NULL;
222     return IDirect3DVolume8_Release((IDirect3DVolume8*) volumeParent);
223 }