volume.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #include "config.h"
  22. #include "d3d9_private.h"
  23. WINE_DEFAULT_DEBUG_CHANNEL(d3d);
  24. /* IDirect3DVolume9 IUnknown parts follow: */
  25. HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 iface, REFIID riid, LPVOID* ppobj) {
  26. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  27. if (IsEqualGUID(riid, &IID_IUnknown)
  28. || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
  29. IDirect3DVolume9Impl_AddRef(iface);
  30. *ppobj = This;
  31. return D3D_OK;
  32. }
  33. WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
  34. return E_NOINTERFACE;
  35. }
  36. ULONG WINAPI IDirect3DVolume9Impl_AddRef(LPDIRECT3DVOLUME9 iface) {
  37. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  38. ULONG ref = InterlockedIncrement(&This->ref);
  39. TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
  40. return ref;
  41. }
  42. ULONG WINAPI IDirect3DVolume9Impl_Release(LPDIRECT3DVOLUME9 iface) {
  43. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  44. ULONG ref = InterlockedDecrement(&This->ref);
  45. TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
  46. if (ref == 0) {
  47. IWineD3DVolume_Release(This->wineD3DVolume);
  48. HeapFree(GetProcessHeap(), 0, This);
  49. }
  50. return ref;
  51. }
  52. /* IDirect3DVolume9 Interface follow: */
  53. HRESULT WINAPI IDirect3DVolume9Impl_GetDevice(LPDIRECT3DVOLUME9 iface, IDirect3DDevice9** ppDevice) {
  54. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  55. IWineD3DDevice *myDevice = NULL;
  56. IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
  57. IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
  58. IWineD3DDevice_Release(myDevice);
  59. return D3D_OK;
  60. }
  61. HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
  62. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  63. return IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
  64. }
  65. HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
  66. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  67. return IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
  68. }
  69. HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(LPDIRECT3DVOLUME9 iface, REFGUID refguid) {
  70. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  71. return IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
  72. }
  73. HRESULT WINAPI IDirect3DVolume9Impl_GetContainer(LPDIRECT3DVOLUME9 iface, REFIID riid, void** ppContainer) {
  74. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  75. HRESULT res;
  76. IUnknown *IWineContainer = NULL;
  77. res = IWineD3DVolume_GetContainer(This->wineD3DVolume, riid, (void **)&IWineContainer);
  78. /* If this works, the only valid container is a child of resource (volumetexture) */
  79. if (res == D3D_OK && NULL != ppContainer) {
  80. IWineD3DResource_GetParent((IWineD3DResource *)IWineContainer, (IUnknown **)ppContainer);
  81. IWineD3DResource_Release((IWineD3DResource *)IWineContainer);
  82. }
  83. return res;
  84. }
  85. HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(LPDIRECT3DVOLUME9 iface, D3DVOLUME_DESC* pDesc) {
  86. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  87. WINED3DVOLUME_DESC wined3ddesc;
  88. UINT tmpInt = -1;
  89. /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
  90. wined3ddesc.Format = &pDesc->Format;
  91. wined3ddesc.Type = &pDesc->Type;
  92. wined3ddesc.Usage = &pDesc->Usage;
  93. wined3ddesc.Pool = &pDesc->Pool;
  94. wined3ddesc.Size = &tmpInt;
  95. wined3ddesc.Width = &pDesc->Width;
  96. wined3ddesc.Height = &pDesc->Height;
  97. wined3ddesc.Depth = &pDesc->Depth;
  98. return IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
  99. }
  100. HRESULT WINAPI IDirect3DVolume9Impl_LockBox(LPDIRECT3DVOLUME9 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
  101. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  102. return IWineD3DVolume_LockBox(This->wineD3DVolume, pLockedVolume, pBox, Flags);
  103. }
  104. HRESULT WINAPI IDirect3DVolume9Impl_UnlockBox(LPDIRECT3DVOLUME9 iface) {
  105. IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
  106. return IWineD3DVolume_UnlockBox(This->wineD3DVolume);
  107. }
  108. IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
  109. {
  110. IDirect3DVolume9Impl_QueryInterface,
  111. IDirect3DVolume9Impl_AddRef,
  112. IDirect3DVolume9Impl_Release,
  113. IDirect3DVolume9Impl_GetDevice,
  114. IDirect3DVolume9Impl_SetPrivateData,
  115. IDirect3DVolume9Impl_GetPrivateData,
  116. IDirect3DVolume9Impl_FreePrivateData,
  117. IDirect3DVolume9Impl_GetContainer,
  118. IDirect3DVolume9Impl_GetDesc,
  119. IDirect3DVolume9Impl_LockBox,
  120. IDirect3DVolume9Impl_UnlockBox
  121. };
  122. /* Internal function called back during the CreateVolumeTexture */
  123. HRESULT WINAPI D3D9CB_CreateVolume(IUnknown *pDevice, UINT Width, UINT Height, UINT Depth,
  124. D3DFORMAT Format, D3DPOOL Pool, DWORD Usage,
  125. IWineD3DVolume **ppVolume,
  126. HANDLE * pSharedHandle) {
  127. IDirect3DVolume9Impl *object;
  128. IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)pDevice;
  129. HRESULT hrc = D3D_OK;
  130. /* Allocate the storage for the device */
  131. object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume9Impl));
  132. if (NULL == object) {
  133. FIXME("Allocation of memory failed\n");
  134. *ppVolume = NULL;
  135. return D3DERR_OUTOFVIDEOMEMORY;
  136. }
  137. object->lpVtbl = &Direct3DVolume9_Vtbl;
  138. object->ref = 1;
  139. hrc = IWineD3DDevice_CreateVolume(This->WineD3DDevice, Width, Height, Depth, Usage, Format,
  140. Pool, ppVolume, pSharedHandle, (IUnknown *)object);
  141. if (hrc != D3D_OK) {
  142. /* free up object */
  143. FIXME("(%p) call to IWineD3DDevice_CreateVolume failed\n", This);
  144. HeapFree(GetProcessHeap(), 0, object);
  145. *ppVolume = NULL;
  146. } else {
  147. *ppVolume = (IWineD3DVolume *)object;
  148. }
  149. return hrc;
  150. }