gdiplus: Add stub for GdipImageRotateFlip.
[wine] / dlls / d3d8 / indexbuffer.c
1 /*
2  * IDirect3DIndexBuffer8 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 /* IDirect3DIndexBuffer8 IUnknown parts follow: */
27 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_QueryInterface(LPDIRECT3DINDEXBUFFER8 iface, REFIID riid, LPVOID *ppobj) {
28     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
29
30     if (IsEqualGUID(riid, &IID_IUnknown)
31         || IsEqualGUID(riid, &IID_IDirect3DResource8)
32         || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer8)) {
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     *ppobj = NULL;
40     return E_NOINTERFACE;
41 }
42
43 static ULONG WINAPI IDirect3DIndexBuffer8Impl_AddRef(LPDIRECT3DINDEXBUFFER8 iface) {
44     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
48
49     return ref;
50 }
51
52 static ULONG WINAPI IDirect3DIndexBuffer8Impl_Release(LPDIRECT3DINDEXBUFFER8 iface) {
53     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
57
58     if (ref == 0) {
59         EnterCriticalSection(&d3d8_cs);
60         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
61         LeaveCriticalSection(&d3d8_cs);
62         IUnknown_Release(This->parentDevice);
63         HeapFree(GetProcessHeap(), 0, This);
64     }
65     return ref;
66 }
67
68 /* IDirect3DIndexBuffer8 IDirect3DResource8 Interface follow: */
69 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDevice(LPDIRECT3DINDEXBUFFER8 iface, IDirect3DDevice8 **ppDevice) {
70     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
71     IWineD3DDevice *wined3d_device;
72     HRESULT hr;
73     TRACE("(%p) Relay\n", This);
74
75     EnterCriticalSection(&d3d8_cs);
76     hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
77     if (SUCCEEDED(hr))
78     {
79         IWineD3DDevice_GetParent(wined3d_device, (IUnknown **)ppDevice);
80         IWineD3DDevice_Release(wined3d_device);
81     }
82     LeaveCriticalSection(&d3d8_cs);
83     return hr;
84 }
85
86 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
87     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
88     HRESULT hr;
89     TRACE("(%p) Relay\n", This);
90
91     EnterCriticalSection(&d3d8_cs);
92     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
93     LeaveCriticalSection(&d3d8_cs);
94     return hr;
95 }
96
97 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
98     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
99     HRESULT hr;
100     TRACE("(%p) Relay\n", This);
101
102     EnterCriticalSection(&d3d8_cs);
103     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
104     LeaveCriticalSection(&d3d8_cs);
105     return hr;
106 }
107
108 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER8 iface, REFGUID refguid) {
109     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
110     HRESULT hr;
111     TRACE("(%p) Relay\n", This);
112
113     EnterCriticalSection(&d3d8_cs);
114     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
115     LeaveCriticalSection(&d3d8_cs);
116     return hr;
117 }
118
119 static DWORD WINAPI IDirect3DIndexBuffer8Impl_SetPriority(LPDIRECT3DINDEXBUFFER8 iface, DWORD PriorityNew) {
120     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
121     DWORD ret;
122     TRACE("(%p) Relay\n", This);
123
124     EnterCriticalSection(&d3d8_cs);
125     ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
126     LeaveCriticalSection(&d3d8_cs);
127     return ret;
128 }
129
130 static DWORD WINAPI IDirect3DIndexBuffer8Impl_GetPriority(LPDIRECT3DINDEXBUFFER8 iface) {
131     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
132     DWORD ret;
133     TRACE("(%p) Relay\n", This);
134
135     EnterCriticalSection(&d3d8_cs);
136     ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
137     LeaveCriticalSection(&d3d8_cs);
138     return ret;
139 }
140
141 static void WINAPI IDirect3DIndexBuffer8Impl_PreLoad(LPDIRECT3DINDEXBUFFER8 iface) {
142     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
143     TRACE("(%p) Relay\n", This);
144
145     EnterCriticalSection(&d3d8_cs);
146     IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
147     LeaveCriticalSection(&d3d8_cs);
148 }
149
150 static D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer8Impl_GetType(LPDIRECT3DINDEXBUFFER8 iface) {
151     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
152     TRACE("(%p)\n", This);
153
154     return D3DRTYPE_INDEXBUFFER;
155 }
156
157 /* IDirect3DIndexBuffer8 Interface follow: */
158 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Lock(LPDIRECT3DINDEXBUFFER8 iface, UINT OffsetToLock, UINT SizeToLock, BYTE **ppbData, DWORD Flags) {
159     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
160     HRESULT hr;
161     TRACE("(%p) Relay\n", This);
162
163     EnterCriticalSection(&d3d8_cs);
164     hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
165     LeaveCriticalSection(&d3d8_cs);
166     return hr;
167 }
168
169 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_Unlock(LPDIRECT3DINDEXBUFFER8 iface) {
170     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
171     HRESULT hr;
172     TRACE("(%p) Relay\n", This);
173
174     EnterCriticalSection(&d3d8_cs);
175     hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
176     LeaveCriticalSection(&d3d8_cs);
177     return hr;
178 }
179
180 static HRESULT WINAPI IDirect3DIndexBuffer8Impl_GetDesc(LPDIRECT3DINDEXBUFFER8 iface, D3DINDEXBUFFER_DESC *pDesc) {
181     IDirect3DIndexBuffer8Impl *This = (IDirect3DIndexBuffer8Impl *)iface;
182     HRESULT hr;
183     WINED3DBUFFER_DESC desc;
184     TRACE("(%p) Relay\n", This);
185
186     EnterCriticalSection(&d3d8_cs);
187     hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
188     LeaveCriticalSection(&d3d8_cs);
189
190     if (SUCCEEDED(hr)) {
191         pDesc->Format = d3dformat_from_wined3dformat(This->format);
192         pDesc->Type = D3DRTYPE_INDEXBUFFER;
193         pDesc->Usage = desc.Usage;
194         pDesc->Pool = desc.Pool;
195         pDesc->Size = desc.Size;
196     }
197
198     return hr;
199 }
200
201
202 const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
203 {
204     /* IUnknown */
205     IDirect3DIndexBuffer8Impl_QueryInterface,
206     IDirect3DIndexBuffer8Impl_AddRef,
207     IDirect3DIndexBuffer8Impl_Release,
208     /* IDirect3DResource8 */
209     IDirect3DIndexBuffer8Impl_GetDevice,
210     IDirect3DIndexBuffer8Impl_SetPrivateData,
211     IDirect3DIndexBuffer8Impl_GetPrivateData,
212     IDirect3DIndexBuffer8Impl_FreePrivateData,
213     IDirect3DIndexBuffer8Impl_SetPriority,
214     IDirect3DIndexBuffer8Impl_GetPriority,
215     IDirect3DIndexBuffer8Impl_PreLoad,
216     IDirect3DIndexBuffer8Impl_GetType,
217     /* IDirect3DIndexBuffer8 */
218     IDirect3DIndexBuffer8Impl_Lock,
219     IDirect3DIndexBuffer8Impl_Unlock,
220     IDirect3DIndexBuffer8Impl_GetDesc
221 };