When we are converting from one sample rate to another, we do have to
[wine] / dlls / d3d9 / indexbuffer.c
1 /*
2  * IDirect3DIndexBuffer9 implementation
3  *
4  * Copyright 2002-2004 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
22 #include "config.h"
23 #include "d3d9_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
26
27 /* IDirect3DIndexBuffer9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
29     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
30
31     if (IsEqualGUID(riid, &IID_IUnknown)
32         || IsEqualGUID(riid, &IID_IDirect3DResource9)
33         || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
34         IDirect3DIndexBuffer9Impl_AddRef(iface);
35         *ppobj = This;
36         return D3D_OK;
37     }
38
39     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
40     return E_NOINTERFACE;
41 }
42
43 ULONG WINAPI IDirect3DIndexBuffer9Impl_AddRef(LPDIRECT3DINDEXBUFFER9 iface) {
44     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
45     ULONG ref = InterlockedIncrement(&This->ref);
46
47     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
48
49     return ref;
50 }
51
52 ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 iface) {
53     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
54     ULONG ref = InterlockedDecrement(&This->ref);
55
56     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
57
58     if (ref == 0) {
59         IWineD3DIndexBuffer_Release(This->wineD3DIndexBuffer);
60         HeapFree(GetProcessHeap(), 0, This);
61     }
62     return ref;
63 }
64
65 /* IDirect3DIndexBuffer9 IDirect3DResource9 Interface follow: */
66 HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetDevice(LPDIRECT3DINDEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
67     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
68     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
69 }
70
71 HRESULT WINAPI IDirect3DIndexBuffer9Impl_SetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
72     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
73     return IWineD3DIndexBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
74 }
75
76 HRESULT WINAPI IDirect3DIndexBuffer9Impl_GetPrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
77     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
78     return IWineD3DIndexBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
79 }
80
81 HRESULT WINAPI IDirect3DIndexBuffer9Impl_FreePrivateData(LPDIRECT3DINDEXBUFFER9 iface, REFGUID refguid) {
82     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
83     return IWineD3DIndexBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
84 }
85
86 DWORD WINAPI IDirect3DIndexBuffer9Impl_SetPriority(LPDIRECT3DINDEXBUFFER9 iface, DWORD PriorityNew) {
87     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
88     return IWineD3DIndexBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
89 }
90
91 DWORD WINAPI IDirect3DIndexBuffer9Impl_GetPriority(LPDIRECT3DINDEXBUFFER9 iface) {
92     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
93     return IWineD3DIndexBuffer_GetPriority(This->wineD3DIndexBuffer);
94 }
95
96 void WINAPI IDirect3DIndexBuffer9Impl_PreLoad(LPDIRECT3DINDEXBUFFER9 iface) {
97     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
98     IWineD3DIndexBuffer_PreLoad(This->wineD3DIndexBuffer);
99     return ;
100 }
101
102 D3DRESOURCETYPE WINAPI IDirect3DIndexBuffer9Impl_GetType(LPDIRECT3DINDEXBUFFER9 iface) {
103     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
104     return IWineD3DIndexBuffer_GetType(This->wineD3DIndexBuffer);
105 }
106
107 /* IDirect3DIndexBuffer9 Interface follow: */
108 HRESULT WINAPI IDirect3DIndexBuffer9Impl_Lock(LPDIRECT3DINDEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
109     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
110     return IWineD3DIndexBuffer_Lock(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
111 }
112
113 HRESULT WINAPI IDirect3DIndexBuffer9Impl_Unlock(LPDIRECT3DINDEXBUFFER9 iface) {
114     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
115     return IWineD3DIndexBuffer_Unlock(This->wineD3DIndexBuffer);
116 }
117
118 HRESULT  WINAPI        IDirect3DIndexBuffer9Impl_GetDesc(LPDIRECT3DINDEXBUFFER9 iface, D3DINDEXBUFFER_DESC *pDesc) {
119     IDirect3DIndexBuffer9Impl *This = (IDirect3DIndexBuffer9Impl *)iface;
120     return IWineD3DIndexBuffer_GetDesc(This->wineD3DIndexBuffer, pDesc);
121 }
122
123
124 IDirect3DIndexBuffer9Vtbl Direct3DIndexBuffer9_Vtbl =
125 {
126     IDirect3DIndexBuffer9Impl_QueryInterface,
127     IDirect3DIndexBuffer9Impl_AddRef,
128     IDirect3DIndexBuffer9Impl_Release,
129     IDirect3DIndexBuffer9Impl_GetDevice,
130     IDirect3DIndexBuffer9Impl_SetPrivateData,
131     IDirect3DIndexBuffer9Impl_GetPrivateData,
132     IDirect3DIndexBuffer9Impl_FreePrivateData,
133     IDirect3DIndexBuffer9Impl_SetPriority,
134     IDirect3DIndexBuffer9Impl_GetPriority,
135     IDirect3DIndexBuffer9Impl_PreLoad,
136     IDirect3DIndexBuffer9Impl_GetType,
137     IDirect3DIndexBuffer9Impl_Lock,
138     IDirect3DIndexBuffer9Impl_Unlock,
139     IDirect3DIndexBuffer9Impl_GetDesc
140 };
141
142
143 /* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
144 HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9 iface, 
145                                                       UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, 
146                                                       IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) {
147     
148     IDirect3DIndexBuffer9Impl *object;
149     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
150     HRESULT hrc = D3D_OK;
151     
152     /* Allocate the storage for the device */
153     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DIndexBuffer9Impl));
154     if (NULL == object) {
155         FIXME("Allocation of memory failed\n");
156         *ppIndexBuffer = NULL;
157         return D3DERR_OUTOFVIDEOMEMORY;
158     }
159
160     object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
161     object->ref = 1;
162     hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage, Format, Pool, &(object->wineD3DIndexBuffer), pSharedHandle, (IUnknown *)object);
163     if (hrc != D3D_OK) {
164         /* free up object */ 
165         FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
166         HeapFree(GetProcessHeap(), 0, object);
167         *ppIndexBuffer = NULL;
168     } else {
169         *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
170     }
171     return hrc;
172 }