Don't define COBJMACROS in objbase.h.
[wine/multimedia.git] / dlls / d3d8 / volume.c
blob32ab930eba94f158741309d0a734a44eff38dcf5
1 /*
2 * IDirect3DVolume8 implementation
4 * Copyright 2002-2003 Jason Edmeades
5 * Raphael Junqueira
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <stdarg.h>
26 #define COBJMACROS
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winuser.h"
33 #include "wingdi.h"
34 #include "wine/debug.h"
36 #include "d3d8_private.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
40 /* IDirect3DVolume IUnknown parts follow: */
41 HRESULT WINAPI IDirect3DVolume8Impl_QueryInterface(LPDIRECT3DVOLUME8 iface, REFIID riid, LPVOID* ppobj) {
42 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
44 if (IsEqualGUID(riid, &IID_IUnknown)
45 || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
46 IDirect3DVolume8Impl_AddRef(iface);
47 *ppobj = This;
48 return D3D_OK;
51 WARN("(%p)->(%s,%p) not found\n", This, debugstr_guid(riid), ppobj);
52 return E_NOINTERFACE;
55 ULONG WINAPI IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface) {
56 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
57 TRACE("(%p) : AddRef from %ld\n", This, This->ref);
58 return ++(This->ref);
61 ULONG WINAPI IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface) {
62 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
63 ULONG ref = --This->ref;
64 TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
65 if (ref == 0) {
66 HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
67 HeapFree(GetProcessHeap(), 0, This);
69 return ref;
72 /* IDirect3DVolume8: */
73 HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface, IDirect3DDevice8** ppDevice) {
74 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
75 TRACE("(%p) : returning %p\n", This, This->Device);
76 *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
78 /* Note Calling this method will increase the internal reference count
79 on the IDirect3DDevice8 interface. */
80 IDirect3DDevice8Impl_AddRef(*ppDevice);
82 return D3D_OK;
85 HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
86 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
87 FIXME("(%p) : stub\n", This);
88 return D3D_OK;
91 HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
92 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
93 FIXME("(%p) : stub\n", This);
94 return D3D_OK;
97 HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid) {
98 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
99 FIXME("(%p) : stub\n", This);
100 return D3D_OK;
103 HRESULT WINAPI IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface, REFIID riid, void** ppContainer) {
104 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
105 TRACE("(%p) : returning %p\n", This, This->Container);
106 *ppContainer = This->Container;
107 IUnknown_AddRef(This->Container);
108 return D3D_OK;
111 HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface, D3DVOLUME_DESC* pDesc) {
112 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
113 TRACE("(%p) : copying into %p\n", This, pDesc);
114 memcpy(pDesc, &This->myDesc, sizeof(D3DVOLUME_DESC));
115 return D3D_OK;
118 HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags) {
119 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
120 FIXME("(%p) : pBox=%p stub\n", This, pBox);
122 /* fixme: should we really lock as such? */
123 TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->allocatedMemory);
125 pLockedVolume->RowPitch = This->bytesPerPixel * This->myDesc.Width; /* Bytes / row */
126 pLockedVolume->SlicePitch = This->bytesPerPixel * This->myDesc.Width * This->myDesc.Height; /* Bytes / slice */
127 if (!pBox) {
128 TRACE("No box supplied - all is ok\n");
129 pLockedVolume->pBits = This->allocatedMemory;
130 This->lockedBox.Left = 0;
131 This->lockedBox.Top = 0;
132 This->lockedBox.Front = 0;
133 This->lockedBox.Right = This->myDesc.Width;
134 This->lockedBox.Bottom = This->myDesc.Height;
135 This->lockedBox.Back = This->myDesc.Depth;
136 } else {
137 TRACE("Lock Box (%p) = l %d, t %d, r %d, b %d, fr %d, ba %d\n", pBox, pBox->Left, pBox->Top, pBox->Right, pBox->Bottom, pBox->Front, pBox->Back);
138 pLockedVolume->pBits = This->allocatedMemory +
139 (pLockedVolume->SlicePitch * pBox->Front) + /* FIXME: is front < back or vica versa? */
140 (pLockedVolume->RowPitch * pBox->Top) +
141 (pBox->Left * This->bytesPerPixel);
142 This->lockedBox.Left = pBox->Left;
143 This->lockedBox.Top = pBox->Top;
144 This->lockedBox.Front = pBox->Front;
145 This->lockedBox.Right = pBox->Right;
146 This->lockedBox.Bottom = pBox->Bottom;
147 This->lockedBox.Back = pBox->Back;
150 if (Flags & (D3DLOCK_NO_DIRTY_UPDATE | D3DLOCK_READONLY)) {
151 /* Don't dirtify */
152 } else {
154 * Dirtify on lock
155 * as seen in msdn docs
157 IDirect3DVolume8Impl_AddDirtyBox(iface, &This->lockedBox);
159 /** Dirtify Container if needed */
160 if (NULL != This->Container) {
161 IDirect3DVolumeTexture8* cont = (IDirect3DVolumeTexture8*) This->Container;
162 D3DRESOURCETYPE containerType = IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) cont);
163 if (containerType == D3DRTYPE_VOLUMETEXTURE) {
164 IDirect3DBaseTexture8Impl* pTexture = (IDirect3DBaseTexture8Impl*) cont;
165 pTexture->Dirty = TRUE;
166 } else {
167 FIXME("Set dirty on container type %d\n", containerType);
172 This->locked = TRUE;
173 TRACE("returning memory@%p rpitch(%d) spitch(%d)\n", pLockedVolume->pBits, pLockedVolume->RowPitch, pLockedVolume->SlicePitch);
174 return D3D_OK;
177 HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) {
178 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
179 if (FALSE == This->locked) {
180 ERR("trying to lock unlocked volume@%p\n", This);
181 return D3DERR_INVALIDCALL;
183 TRACE("(%p) : unlocking volume\n", This);
184 This->locked = FALSE;
185 memset(&This->lockedBox, 0, sizeof(RECT));
186 return D3D_OK;
190 IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
192 IDirect3DVolume8Impl_QueryInterface,
193 IDirect3DVolume8Impl_AddRef,
194 IDirect3DVolume8Impl_Release,
195 IDirect3DVolume8Impl_GetDevice,
196 IDirect3DVolume8Impl_SetPrivateData,
197 IDirect3DVolume8Impl_GetPrivateData,
198 IDirect3DVolume8Impl_FreePrivateData,
199 IDirect3DVolume8Impl_GetContainer,
200 IDirect3DVolume8Impl_GetDesc,
201 IDirect3DVolume8Impl_LockBox,
202 IDirect3DVolume8Impl_UnlockBox
206 HRESULT WINAPI IDirect3DVolume8Impl_CleanDirtyBox(LPDIRECT3DVOLUME8 iface) {
207 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
208 This->Dirty = FALSE;
209 This->lockedBox.Left = This->myDesc.Width;
210 This->lockedBox.Top = This->myDesc.Height;
211 This->lockedBox.Front = This->myDesc.Depth;
212 This->lockedBox.Right = 0;
213 This->lockedBox.Bottom = 0;
214 This->lockedBox.Back = 0;
215 return D3D_OK;
219 * Raphael:
220 * very stupid way to handle multiple dirty box but it works :)
222 HRESULT WINAPI IDirect3DVolume8Impl_AddDirtyBox(LPDIRECT3DVOLUME8 iface, CONST D3DBOX* pDirtyBox) {
223 IDirect3DVolume8Impl *This = (IDirect3DVolume8Impl *)iface;
224 This->Dirty = TRUE;
225 if (NULL != pDirtyBox) {
226 This->lockedBox.Left = min(This->lockedBox.Left, pDirtyBox->Left);
227 This->lockedBox.Top = min(This->lockedBox.Top, pDirtyBox->Top);
228 This->lockedBox.Front = min(This->lockedBox.Front, pDirtyBox->Front);
229 This->lockedBox.Right = max(This->lockedBox.Right, pDirtyBox->Right);
230 This->lockedBox.Bottom = max(This->lockedBox.Bottom, pDirtyBox->Bottom);
231 This->lockedBox.Back = max(This->lockedBox.Back, pDirtyBox->Back);
232 } else {
233 This->lockedBox.Left = 0;
234 This->lockedBox.Top = 0;
235 This->lockedBox.Front = 0;
236 This->lockedBox.Right = This->myDesc.Width;
237 This->lockedBox.Bottom = This->myDesc.Height;
238 This->lockedBox.Back = This->myDesc.Depth;
240 return D3D_OK;