d3d8: Get rid of resource.c.
[wine] / dlls / d3d8 / vertexbuffer.c
1 /*
2  * IDirect3DVertexBuffer8 implementation
3  *
4  * Copyright 2005 Oliver Stieber
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "d3d8_private.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
25
26 /* IDirect3DVertexBuffer8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
29
30     if (IsEqualGUID(riid, &IID_IUnknown)
31         || IsEqualGUID(riid, &IID_IDirect3DResource8)
32         || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer8)) {
33         IUnknown_AddRef(iface);
34         *ppobj = This;
35         return S_OK;
36     }
37
38     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
39
40     *ppobj = NULL;
41     return E_NOINTERFACE;
42 }
43
44 static ULONG WINAPI IDirect3DVertexBuffer8Impl_AddRef(LPDIRECT3DVERTEXBUFFER8 iface) {
45     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
46     ULONG ref = InterlockedIncrement(&This->ref);
47
48     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
49
50     return ref;
51 }
52
53 static ULONG WINAPI IDirect3DVertexBuffer8Impl_Release(LPDIRECT3DVERTEXBUFFER8 iface) {
54     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
55     ULONG ref = InterlockedDecrement(&This->ref);
56
57     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
58
59     if (ref == 0) {
60         EnterCriticalSection(&d3d8_cs);
61         IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
62         LeaveCriticalSection(&d3d8_cs);
63         IUnknown_Release(This->parentDevice);
64         HeapFree(GetProcessHeap(), 0, This);
65     }
66
67     return ref;
68 }
69
70 /* IDirect3DVertexBuffer8 IDirect3DResource8 Interface follow: */
71 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDevice(LPDIRECT3DVERTEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
72     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
73     IWineD3DDevice *wined3d_device;
74     HRESULT hr;
75     TRACE("(%p) Relay\n", This);
76
77     EnterCriticalSection(&d3d8_cs);
78     hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
79     if (SUCCEEDED(hr))
80     {
81         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
82         IWineD3DDevice_Release(wined3d_device);
83     }
84     LeaveCriticalSection(&d3d8_cs);
85     return hr;
86 }
87
88 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
89     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
90     HRESULT hr;
91     TRACE("(%p) Relay\n", This);
92
93     EnterCriticalSection(&d3d8_cs);
94     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
95     LeaveCriticalSection(&d3d8_cs);
96     return hr;
97 }
98
99 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
100     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
101     HRESULT hr;
102     TRACE("(%p) Relay\n", This);
103
104     EnterCriticalSection(&d3d8_cs);
105     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
106     LeaveCriticalSection(&d3d8_cs);
107     return hr;
108 }
109
110 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER8 iface, REFGUID refguid) {
111     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
112     HRESULT hr;
113     TRACE("(%p) Relay\n", This);
114
115     EnterCriticalSection(&d3d8_cs);
116     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
117     LeaveCriticalSection(&d3d8_cs);
118     return hr;
119 }
120
121 static DWORD WINAPI IDirect3DVertexBuffer8Impl_SetPriority(LPDIRECT3DVERTEXBUFFER8 iface, DWORD PriorityNew) {
122     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
123     DWORD ret;
124     TRACE("(%p) Relay\n", This);
125
126     EnterCriticalSection(&d3d8_cs);
127     ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
128     LeaveCriticalSection(&d3d8_cs);
129     return ret;
130 }
131
132 static DWORD WINAPI IDirect3DVertexBuffer8Impl_GetPriority(LPDIRECT3DVERTEXBUFFER8 iface) {
133     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
134     DWORD ret;
135     TRACE("(%p) Relay\n", This);
136
137     EnterCriticalSection(&d3d8_cs);
138     ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
139     LeaveCriticalSection(&d3d8_cs);
140     return ret;
141 }
142
143 static void WINAPI IDirect3DVertexBuffer8Impl_PreLoad(LPDIRECT3DVERTEXBUFFER8 iface) {
144     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
145     TRACE("(%p) Relay\n", This);
146
147     EnterCriticalSection(&d3d8_cs);
148     IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
149     LeaveCriticalSection(&d3d8_cs);
150 }
151
152 static D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer8Impl_GetType(LPDIRECT3DVERTEXBUFFER8 iface) {
153     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
154     D3DRESOURCETYPE type;
155     TRACE("(%p) Relay\n", This);
156
157     EnterCriticalSection(&d3d8_cs);
158     type = IWineD3DBuffer_GetType(This->wineD3DVertexBuffer);
159     LeaveCriticalSection(&d3d8_cs);
160     return type;
161 }
162
163 /* IDirect3DVertexBuffer8 Interface follow: */
164 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Lock(LPDIRECT3DVERTEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
165     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
166     HRESULT hr;
167     TRACE("(%p) Relay\n", This);
168
169     EnterCriticalSection(&d3d8_cs);
170     hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
171     LeaveCriticalSection(&d3d8_cs);
172     return hr;
173 }
174
175 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface) {
176     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
177     HRESULT hr;
178     TRACE("(%p) Relay\n", This);
179
180     EnterCriticalSection(&d3d8_cs);
181     hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
182     LeaveCriticalSection(&d3d8_cs);
183     return hr;
184 }
185
186 static HRESULT WINAPI IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc) {
187     IDirect3DVertexBuffer8Impl *This = (IDirect3DVertexBuffer8Impl *)iface;
188     HRESULT hr;
189     TRACE("(%p) Relay\n", This);
190
191     EnterCriticalSection(&d3d8_cs);
192     hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, (WINED3DVERTEXBUFFER_DESC *)pDesc);
193     LeaveCriticalSection(&d3d8_cs);
194
195     if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
196
197     return hr;
198 }
199
200 const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
201 {
202     /* IUnknown */
203     IDirect3DVertexBuffer8Impl_QueryInterface,
204     IDirect3DVertexBuffer8Impl_AddRef,
205     IDirect3DVertexBuffer8Impl_Release,
206     /* IDirect3DResource8 */
207     IDirect3DVertexBuffer8Impl_GetDevice,
208     IDirect3DVertexBuffer8Impl_SetPrivateData,
209     IDirect3DVertexBuffer8Impl_GetPrivateData,
210     IDirect3DVertexBuffer8Impl_FreePrivateData,
211     IDirect3DVertexBuffer8Impl_SetPriority,
212     IDirect3DVertexBuffer8Impl_GetPriority,
213     IDirect3DVertexBuffer8Impl_PreLoad,
214     IDirect3DVertexBuffer8Impl_GetType,
215     /* IDirect3DVertexBuffer8 */
216     IDirect3DVertexBuffer8Impl_Lock,
217     IDirect3DVertexBuffer8Impl_Unlock,
218     IDirect3DVertexBuffer8Impl_GetDesc
219 };