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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*
|
---|
23 | * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
24 | * other than GPL or LGPL is available it will apply instead, Sun elects to use only
|
---|
25 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
26 | * a choice of LGPL license versions is made available with the language indicating
|
---|
27 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
28 | * of the LGPL is applied is otherwise unspecified.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #include "config.h"
|
---|
32 | #include "d3d9_private.h"
|
---|
33 |
|
---|
34 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
35 |
|
---|
36 | /* IDirect3DVolume9 IUnknown parts follow: */
|
---|
37 | static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 iface, REFIID riid, LPVOID* ppobj) {
|
---|
38 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
39 |
|
---|
40 | if (IsEqualGUID(riid, &IID_IUnknown)
|
---|
41 | || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
|
---|
42 | IDirect3DVolume9_AddRef(iface);
|
---|
43 | *ppobj = This;
|
---|
44 | return S_OK;
|
---|
45 | }
|
---|
46 |
|
---|
47 | WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
---|
48 | *ppobj = NULL;
|
---|
49 | return E_NOINTERFACE;
|
---|
50 | }
|
---|
51 |
|
---|
52 | static ULONG WINAPI IDirect3DVolume9Impl_AddRef(LPDIRECT3DVOLUME9 iface) {
|
---|
53 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
54 |
|
---|
55 | TRACE("(%p)\n", This);
|
---|
56 |
|
---|
57 | if (This->forwardReference) {
|
---|
58 | /* Forward refcounting */
|
---|
59 | TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
|
---|
60 | return IUnknown_AddRef(This->forwardReference);
|
---|
61 | } else {
|
---|
62 | /* No container, handle our own refcounting */
|
---|
63 | ULONG ref = InterlockedIncrement(&This->ref);
|
---|
64 | TRACE("(%p) : AddRef from %d\n", This, ref - 1);
|
---|
65 | return ref;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | static ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
|
---|
70 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
71 |
|
---|
72 | TRACE("(%p)\n", This);
|
---|
73 |
|
---|
74 | if (This->forwardReference) {
|
---|
75 | /* Forward refcounting */
|
---|
76 | TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
|
---|
77 | return IUnknown_Release(This->forwardReference);
|
---|
78 | } else {
|
---|
79 | /* No container, handle our own refcounting */
|
---|
80 | ULONG ref = InterlockedDecrement(&This->ref);
|
---|
81 | TRACE("(%p) : ReleaseRef to %d\n", This, ref);
|
---|
82 |
|
---|
83 | if (ref == 0) {
|
---|
84 | IWineD3DVolume_Release(This->wineD3DVolume);
|
---|
85 | HeapFree(GetProcessHeap(), 0, This);
|
---|
86 | }
|
---|
87 |
|
---|
88 | return ref;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | /* IDirect3DVolume9 Interface follow: */
|
---|
93 | static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
|
---|
94 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
95 | IWineD3DDevice *myDevice = NULL;
|
---|
96 |
|
---|
97 | IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
|
---|
98 | IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
|
---|
99 | IWineD3DDevice_Release(myDevice);
|
---|
100 | return D3D_OK;
|
---|
101 | }
|
---|
102 |
|
---|
103 | static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
|
---|
104 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
105 | TRACE("(%p) Relay\n", This);
|
---|
106 | return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
|
---|
107 | }
|
---|
108 |
|
---|
109 | static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
|
---|
110 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
111 | TRACE("(%p) Relay\n", This);
|
---|
112 | return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
|
---|
113 | }
|
---|
114 |
|
---|
115 | static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
|
---|
116 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
117 | TRACE("(%p) Relay\n", This);
|
---|
118 | return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
|
---|
119 | }
|
---|
120 |
|
---|
121 | static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
|
---|
122 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
123 | HRESULT res;
|
---|
124 |
|
---|
125 | TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
|
---|
126 |
|
---|
127 | if (!This->container) return E_NOINTERFACE;
|
---|
128 |
|
---|
129 | if (!ppContainer) {
|
---|
130 | ERR("Called without a valid ppContainer.\n");
|
---|
131 | }
|
---|
132 |
|
---|
133 | res = IUnknown_QueryInterface(This->container, riid, ppContainer);
|
---|
134 |
|
---|
135 | TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
|
---|
136 |
|
---|
137 | return res;
|
---|
138 | }
|
---|
139 |
|
---|
140 | static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
|
---|
141 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
142 | WINED3DVOLUME_DESC wined3ddesc;
|
---|
143 | UINT tmpInt = -1;
|
---|
144 |
|
---|
145 | TRACE("(%p) Relay\n", This);
|
---|
146 |
|
---|
147 | /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
|
---|
148 | wined3ddesc.Format = (WINED3DFORMAT *)&pDesc->Format;
|
---|
149 | wined3ddesc.Type = (WINED3DRESOURCETYPE *)&pDesc->Type;
|
---|
150 | wined3ddesc.Usage = &pDesc->Usage;
|
---|
151 | wined3ddesc.Pool = (WINED3DPOOL *) &pDesc->Pool;
|
---|
152 | wined3ddesc.Size = &tmpInt;
|
---|
153 | wined3ddesc.Width = &pDesc->Width;
|
---|
154 | wined3ddesc.Height = &pDesc->Height;
|
---|
155 | wined3ddesc.Depth = &pDesc->Depth;
|
---|
156 |
|
---|
157 | return IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
|
---|
158 | }
|
---|
159 |
|
---|
160 | static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
|
---|
161 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
162 | TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
|
---|
163 | return IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume, (CONST WINED3DBOX *)pBox, Flags);
|
---|
164 | }
|
---|
165 |
|
---|
166 | static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
|
---|
167 | IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
|
---|
168 | TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
|
---|
169 | return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
|
---|
170 | }
|
---|
171 |
|
---|
172 | static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
|
---|
173 | {
|
---|
174 | /* IUnknown */
|
---|
175 | IDirect3DVolume9Impl_QueryInterface,
|
---|
176 | IDirect3DVolume9Impl_AddRef,
|
---|
177 | IDirect3DVolume9Impl_Release,
|
---|
178 | /* IDirect3DVolume9 */
|
---|
179 | IDirect3DVolume9Impl_GetDevice,
|
---|
180 | IDirect3DVolume9Impl_SetPrivateData,
|
---|
181 | IDirect3DVolume9Impl_GetPrivateData,
|
---|
182 | IDirect3DVolume9Impl_FreePrivateData,
|
---|
183 | IDirect3DVolume9Impl_GetContainer,
|
---|
184 | IDirect3DVolume9Impl_GetDesc,
|
---|
185 | IDirect3DVolume9Impl_LockBox,
|
---|
186 | IDirect3DVolume9Impl_UnlockBox
|
---|
187 | };
|
---|
188 |
|
---|
189 |
|
---|
190 | /* Internal function called back during the CreateVolumeTexture */
|
---|
191 | HRESULT WINAPI D3D9CB_CreateVolume(IUnknown *pDevice, IUnknown *pSuperior, UINT Width, UINT Height, UINT Depth,
|
---|
192 | WINED3DFORMAT Format, WINED3DPOOL Pool, DWORD Usage,
|
---|
193 | IWineD3DVolume **ppVolume,
|
---|
194 | HANDLE * pSharedHandle) {
|
---|
195 | IDirect3DVolume9Impl *object;
|
---|
196 | IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)pDevice;
|
---|
197 | HRESULT hrc = D3D_OK;
|
---|
198 |
|
---|
199 | /* Allocate the storage for the device */
|
---|
200 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume9Impl));
|
---|
201 | if (NULL == object) {
|
---|
202 | FIXME("Allocation of memory failed\n");
|
---|
203 | *ppVolume = NULL;
|
---|
204 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
205 | }
|
---|
206 |
|
---|
207 | object->lpVtbl = &Direct3DVolume9_Vtbl;
|
---|
208 | object->ref = 1;
|
---|
209 | hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage & WINED3DUSAGE_MASK, Format,
|
---|
210 | Pool, &object->wineD3DVolume, pSharedHandle, (IUnknown *)object);
|
---|
211 | if (hrc != D3D_OK) {
|
---|
212 | /* free up object */
|
---|
213 | FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This);
|
---|
214 | HeapFree(GetProcessHeap(), 0, object);
|
---|
215 | *ppVolume = NULL;
|
---|
216 | } else {
|
---|
217 | *ppVolume = object->wineD3DVolume;
|
---|
218 | object->container = pSuperior;
|
---|
219 | object->forwardReference = pSuperior;
|
---|
220 | }
|
---|
221 | TRACE("(%p) Created volume %p\n", This, *ppVolume);
|
---|
222 | return hrc;
|
---|
223 | }
|
---|
224 |
|
---|
225 | ULONG WINAPI D3D9CB_DestroyVolume(IWineD3DVolume *pVolume) {
|
---|
226 | IDirect3DVolume9Impl* volumeParent;
|
---|
227 |
|
---|
228 | IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
|
---|
229 | /* GetParent's AddRef was forwarded to an object in destruction.
|
---|
230 | * Releasing it here again would cause an endless recursion. */
|
---|
231 | volumeParent->forwardReference = NULL;
|
---|
232 | return IDirect3DVolume9_Release((IDirect3DVolume9*) volumeParent);
|
---|
233 | }
|
---|