2 * IDirect3DVolume9 implementation
4 * Copyright 2002-2005 Jason Edmeades
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.
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.
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
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 /* IDirect3DVolume9 IUnknown parts follow: */
28 static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 iface, REFIID riid, LPVOID* ppobj) {
29 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
31 if (IsEqualGUID(riid, &IID_IUnknown)
32 || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
33 IDirect3DVolume9_AddRef(iface);
38 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43 static ULONG WINAPI IDirect3DVolume9Impl_AddRef(LPDIRECT3DVOLUME9 iface) {
44 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
46 TRACE("(%p)\n", This);
48 if (This->forwardReference) {
49 /* Forward refcounting */
50 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
51 return IUnknown_AddRef(This->forwardReference);
53 /* No container, handle our own refcounting */
54 ULONG ref = InterlockedIncrement(&This->ref);
55 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
60 static ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
61 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
63 TRACE("(%p)\n", This);
65 if (This->forwardReference) {
66 /* Forward refcounting */
67 TRACE("(%p) : Forwarding to %p\n", This, This->forwardReference);
68 return IUnknown_Release(This->forwardReference);
70 /* No container, handle our own refcounting */
71 ULONG ref = InterlockedDecrement(&This->ref);
72 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
75 EnterCriticalSection(&d3d9_cs);
76 IWineD3DVolume_Release(This->wineD3DVolume);
77 LeaveCriticalSection(&d3d9_cs);
78 HeapFree(GetProcessHeap(), 0, This);
85 /* IDirect3DVolume9 Interface follow: */
86 static HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
87 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
88 IWineD3DDevice *myDevice = NULL;
90 TRACE("iface %p, ppDevice %p\n", iface, ppDevice);
92 EnterCriticalSection(&d3d9_cs);
94 IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
95 IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
96 IWineD3DDevice_Release(myDevice);
98 LeaveCriticalSection(&d3d9_cs);
103 static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
104 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
107 TRACE("(%p) Relay\n", This);
109 EnterCriticalSection(&d3d9_cs);
111 hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
113 LeaveCriticalSection(&d3d9_cs);
118 static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
119 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
122 TRACE("(%p) Relay\n", This);
124 EnterCriticalSection(&d3d9_cs);
126 hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
128 LeaveCriticalSection(&d3d9_cs);
133 static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
134 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
137 TRACE("(%p) Relay\n", This);
139 EnterCriticalSection(&d3d9_cs);
141 hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
143 LeaveCriticalSection(&d3d9_cs);
148 static HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
149 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
152 TRACE("(This %p, riid %s, ppContainer %p)\n", This, debugstr_guid(riid), ppContainer);
154 if (!This->container) return E_NOINTERFACE;
157 ERR("Called without a valid ppContainer.\n");
160 res = IUnknown_QueryInterface(This->container, riid, ppContainer);
162 TRACE("Returning ppContainer %p, *ppContainer %p\n", ppContainer, *ppContainer);
167 static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
168 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
169 WINED3DVOLUME_DESC wined3ddesc;
172 TRACE("(%p) Relay\n", This);
174 EnterCriticalSection(&d3d9_cs);
176 hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
178 LeaveCriticalSection(&d3d9_cs);
182 pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
183 pDesc->Type = wined3ddesc.Type;
184 pDesc->Usage = wined3ddesc.Usage;
185 pDesc->Pool = wined3ddesc.Pool;
186 pDesc->Width = wined3ddesc.Width;
187 pDesc->Height = wined3ddesc.Height;
188 pDesc->Depth = wined3ddesc.Depth;
194 static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
195 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
198 TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
200 EnterCriticalSection(&d3d9_cs);
202 hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume,
203 (const WINED3DBOX *)pBox, Flags);
205 LeaveCriticalSection(&d3d9_cs);
210 static HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
211 IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
214 TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
216 EnterCriticalSection(&d3d9_cs);
218 hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
220 LeaveCriticalSection(&d3d9_cs);
225 const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
228 IDirect3DVolume9Impl_QueryInterface,
229 IDirect3DVolume9Impl_AddRef,
230 IDirect3DVolume9Impl_Release,
231 /* IDirect3DVolume9 */
232 IDirect3DVolume9Impl_GetDevice,
233 IDirect3DVolume9Impl_SetPrivateData,
234 IDirect3DVolume9Impl_GetPrivateData,
235 IDirect3DVolume9Impl_FreePrivateData,
236 IDirect3DVolume9Impl_GetContainer,
237 IDirect3DVolume9Impl_GetDesc,
238 IDirect3DVolume9Impl_LockBox,
239 IDirect3DVolume9Impl_UnlockBox
242 ULONG WINAPI D3D9CB_DestroyVolume(IWineD3DVolume *pVolume) {
243 IDirect3DVolume9Impl* volumeParent;
245 IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
246 /* GetParent's AddRef was forwarded to an object in destruction.
247 * Releasing it here again would cause an endless recursion. */
248 volumeParent->forwardReference = NULL;
249 return IDirect3DVolume9_Release((IDirect3DVolume9*) volumeParent);