Fixed a race condition on RPC worker thread creation, and a typo.
[wine] / dlls / d3d8 / volume.c
1 /*
2  * IDirect3DVolume8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27 #include "wine/debug.h"
28
29 #include "d3d8_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
32
33 /* IDirect3DVolume IUnknown parts follow: */
34 HRESULT WINAPI IDirect3DVolume8Impl_QueryInterface(LPDIRECT3DVOLUME8 iface,REFIID riid,LPVOID *ppobj)
35 {
36     ICOM_THIS(IDirect3DVolume8Impl,iface);
37
38     if (IsEqualGUID(riid, &IID_IUnknown)
39         || IsEqualGUID(riid, &IID_IDirect3DVolume8)) {
40         IDirect3DVolume8Impl_AddRef(iface);
41         *ppobj = This;
42         return D3D_OK;
43     }
44
45     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
46     return E_NOINTERFACE;
47 }
48
49 ULONG WINAPI IDirect3DVolume8Impl_AddRef(LPDIRECT3DVOLUME8 iface) {
50     ICOM_THIS(IDirect3DVolume8Impl,iface);
51     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
52     return ++(This->ref);
53 }
54
55 ULONG WINAPI IDirect3DVolume8Impl_Release(LPDIRECT3DVOLUME8 iface) {
56     ICOM_THIS(IDirect3DVolume8Impl,iface);
57     ULONG ref = --This->ref;
58     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
59     if (ref == 0) {
60         HeapFree(GetProcessHeap(), 0, This->allocatedMemory);
61         HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* IDirect3DVolume8: */
67 HRESULT WINAPI IDirect3DVolume8Impl_GetDevice(LPDIRECT3DVOLUME8 iface, IDirect3DDevice8** ppDevice) {
68     ICOM_THIS(IDirect3DVolume8Impl,iface);
69     TRACE("(%p) : returning %p\n", This, This->Device);
70     *ppDevice = (LPDIRECT3DDEVICE8) This->Device;
71
72     /* Note  Calling this method will increase the internal reference count 
73        on the IDirect3DDevice8 interface. */
74     IDirect3DDevice8Impl_AddRef(*ppDevice);
75
76     return D3D_OK;
77 }
78 HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
79     ICOM_THIS(IDirect3DVolume8Impl,iface);
80     FIXME("(%p) : stub\n", This);    return D3D_OK;
81 }
82 HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(LPDIRECT3DVOLUME8 iface, REFGUID  refguid, void* pData, DWORD* pSizeOfData) {
83     ICOM_THIS(IDirect3DVolume8Impl,iface);
84     FIXME("(%p) : stub\n", This);    return D3D_OK;
85 }
86 HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(LPDIRECT3DVOLUME8 iface, REFGUID refguid) {
87     ICOM_THIS(IDirect3DVolume8Impl,iface);
88     FIXME("(%p) : stub\n", This);    return D3D_OK;
89 }
90
91 HRESULT WINAPI IDirect3DVolume8Impl_GetContainer(LPDIRECT3DVOLUME8 iface, REFIID riid, void** ppContainer) {
92     ICOM_THIS(IDirect3DVolume8Impl,iface);
93     TRACE("(%p) : returning %p\n", This, This->Container);
94     *ppContainer = This->Container;
95     return D3D_OK;
96 }
97 HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(LPDIRECT3DVOLUME8 iface, D3DVOLUME_DESC* pDesc) {
98     ICOM_THIS(IDirect3DVolume8Impl,iface);
99     TRACE("(%p) : copying into %p\n", This, pDesc);
100     memcpy(pDesc, &This->myDesc, sizeof(D3DVOLUME_DESC));
101     return D3D_OK;
102 }
103 HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox, DWORD Flags) {
104     ICOM_THIS(IDirect3DVolume8Impl,iface);
105     FIXME("(%p) : pBox=%p stub\n", This, pBox);    
106
107     /* fixme: should we really lock as such? */
108     TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->allocatedMemory);
109
110     pLockedVolume->RowPitch   = This->bytesPerPixel * This->myDesc.Width;                        /* Bytes / row   */
111     pLockedVolume->SlicePitch = This->bytesPerPixel * This->myDesc.Width * This->myDesc.Height;  /* Bytes / slice */
112     if (!pBox) {
113         TRACE("No box supplied - all is ok\n");
114         pLockedVolume->pBits = This->allocatedMemory;
115     } else {
116         TRACE("Lock Box (%p) = l %d, t %d, r %d, b %d, fr %d, ba %d\n", pBox, pBox->Left, pBox->Top, 
117                   pBox->Right, pBox->Bottom, pBox->Front, pBox->Back);
118         pLockedVolume->pBits = This->allocatedMemory + 
119             (pLockedVolume->SlicePitch * pBox->Front) + /* FIXME: is front < back or vica versa? */
120             (pLockedVolume->RowPitch * pBox->Top) + 
121             (pBox->Left * This->bytesPerPixel);
122     }
123     TRACE("returning pBits=%p, rpitch=%d, spitch=%d\n", pLockedVolume->pBits, pLockedVolume->RowPitch, pLockedVolume->SlicePitch);
124     return D3D_OK;
125
126
127
128     return D3D_OK;
129 }
130 HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface) {
131     ICOM_THIS(IDirect3DVolume8Impl,iface);
132     TRACE("(%p) : stub\n", This);
133     if (This->Container) {
134         IDirect3DVolumeTexture8 *cont = This->Container;
135
136         int containerType = IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) cont);
137         if (containerType == D3DRTYPE_VOLUMETEXTURE) {
138             IDirect3DTexture8Impl *pTexture = (IDirect3DTexture8Impl *)cont;
139             pTexture->Dirty = TRUE;
140         } else {
141             FIXME("Set dirty on container type %d\n", containerType);
142         }
143     }
144     return D3D_OK;
145 }
146
147
148 ICOM_VTABLE(IDirect3DVolume8) Direct3DVolume8_Vtbl =
149 {
150     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
151     IDirect3DVolume8Impl_QueryInterface,
152     IDirect3DVolume8Impl_AddRef,
153     IDirect3DVolume8Impl_Release,
154     IDirect3DVolume8Impl_GetDevice,
155     IDirect3DVolume8Impl_SetPrivateData,
156     IDirect3DVolume8Impl_GetPrivateData,
157     IDirect3DVolume8Impl_FreePrivateData,
158     IDirect3DVolume8Impl_GetContainer,
159     IDirect3DVolume8Impl_GetDesc,
160     IDirect3DVolume8Impl_LockBox,
161     IDirect3DVolume8Impl_UnlockBox
162 };