GetCPInfo should return FALSE if called with NULL info buffer.
[wine] / dlls / d3d9 / vertexbuffer.c
1 /*
2  * IDirect3DVertexBuffer9 implementation
3  *
4  * Copyright 2002-2004 Jason Edmeades
5  * Copyright 2002-2004 Raphael Junqueira
6  * Copyright 2005 Oliver Stieber
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28 /* IDirect3DVertexBuffer9 IUnknown parts follow: */
29 HRESULT WINAPI IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEXBUFFER9 iface, REFIID riid, LPVOID* ppobj) {
30     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
31
32     if (IsEqualGUID(riid, &IID_IUnknown)
33         || IsEqualGUID(riid, &IID_IDirect3DResource9)
34         || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)) {
35         IUnknown_AddRef(iface);
36         *ppobj = This;
37         return D3D_OK;
38     }
39
40     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41     return E_NOINTERFACE;
42 }
43
44 ULONG WINAPI IDirect3DVertexBuffer9Impl_AddRef(LPDIRECT3DVERTEXBUFFER9 iface) {
45     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
46     ULONG ref = InterlockedIncrement(&This->ref);
47
48     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
49
50     return ref;
51 }
52
53 ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 iface) {
54     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
55     ULONG ref = InterlockedDecrement(&This->ref);
56
57     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
58
59     if (ref == 0) {
60         IWineD3DVertexBuffer_Release(This->wineD3DVertexBuffer);
61         HeapFree(GetProcessHeap(), 0, This);
62     }
63     return ref;
64 }
65
66 /* IDirect3DVertexBuffer9 IDirect3DResource9 Interface follow: */
67 HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDevice(LPDIRECT3DVERTEXBUFFER9 iface, IDirect3DDevice9** ppDevice) {
68     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
69     TRACE("(%p) Relay\n", This);
70     return IDirect3DResource9Impl_GetDevice((LPDIRECT3DRESOURCE9) This, ppDevice);
71 }
72
73 HRESULT WINAPI IDirect3DVertexBuffer9Impl_SetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
74     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
75     TRACE("(%p) Relay\n", This);
76     return IWineD3DVertexBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
77 }
78
79 HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetPrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
80     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
81     TRACE("(%p) Relay\n", This);
82     return IWineD3DVertexBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
83 }
84
85 HRESULT WINAPI IDirect3DVertexBuffer9Impl_FreePrivateData(LPDIRECT3DVERTEXBUFFER9 iface, REFGUID refguid) {
86     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
87     TRACE("(%p) Relay\n", This);
88     return IWineD3DVertexBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
89 }
90
91 DWORD WINAPI IDirect3DVertexBuffer9Impl_SetPriority(LPDIRECT3DVERTEXBUFFER9 iface, DWORD PriorityNew) {
92     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
93     TRACE("(%p) Relay\n", This);
94     return IWineD3DVertexBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
95 }
96
97 DWORD WINAPI IDirect3DVertexBuffer9Impl_GetPriority(LPDIRECT3DVERTEXBUFFER9 iface) {
98     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
99     TRACE("(%p) Relay\n", This);
100     return IWineD3DVertexBuffer_GetPriority(This->wineD3DVertexBuffer);
101 }
102
103 void WINAPI IDirect3DVertexBuffer9Impl_PreLoad(LPDIRECT3DVERTEXBUFFER9 iface) {
104     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
105     TRACE("(%p) Relay\n", This);
106     IWineD3DVertexBuffer_PreLoad(This->wineD3DVertexBuffer);
107     return ;
108 }
109
110 D3DRESOURCETYPE WINAPI IDirect3DVertexBuffer9Impl_GetType(LPDIRECT3DVERTEXBUFFER9 iface) {
111     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
112     TRACE("(%p) Relay\n", This);
113     return IWineD3DVertexBuffer_GetType(This->wineD3DVertexBuffer);
114 }
115
116 /* IDirect3DVertexBuffer9 Interface follow: */
117 HRESULT WINAPI IDirect3DVertexBuffer9Impl_Lock(LPDIRECT3DVERTEXBUFFER9 iface, UINT OffsetToLock, UINT SizeToLock, void** ppbData, DWORD Flags) {
118     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
119     TRACE("(%p) Relay\n", This);
120     return IWineD3DVertexBuffer_Lock(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
121 }
122
123 HRESULT WINAPI IDirect3DVertexBuffer9Impl_Unlock(LPDIRECT3DVERTEXBUFFER9 iface) {
124     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
125     TRACE("(%p) Relay\n", This);
126     return IWineD3DVertexBuffer_Unlock(This->wineD3DVertexBuffer);
127 }
128
129 HRESULT WINAPI IDirect3DVertexBuffer9Impl_GetDesc(LPDIRECT3DVERTEXBUFFER9 iface, D3DVERTEXBUFFER_DESC* pDesc) {
130     IDirect3DVertexBuffer9Impl *This = (IDirect3DVertexBuffer9Impl *)iface;
131     TRACE("(%p) Relay\n", This);
132     return IWineD3DVertexBuffer_GetDesc(This->wineD3DVertexBuffer, pDesc);
133 }
134
135 IDirect3DVertexBuffer9Vtbl Direct3DVertexBuffer9_Vtbl =
136 {
137     IDirect3DVertexBuffer9Impl_QueryInterface,
138     IDirect3DVertexBuffer9Impl_AddRef,
139     IDirect3DVertexBuffer9Impl_Release,
140     IDirect3DVertexBuffer9Impl_GetDevice,
141     IDirect3DVertexBuffer9Impl_SetPrivateData,
142     IDirect3DVertexBuffer9Impl_GetPrivateData,
143     IDirect3DVertexBuffer9Impl_FreePrivateData,
144     IDirect3DVertexBuffer9Impl_SetPriority,
145     IDirect3DVertexBuffer9Impl_GetPriority,
146     IDirect3DVertexBuffer9Impl_PreLoad,
147     IDirect3DVertexBuffer9Impl_GetType,
148     IDirect3DVertexBuffer9Impl_Lock,
149     IDirect3DVertexBuffer9Impl_Unlock,
150     IDirect3DVertexBuffer9Impl_GetDesc
151 };
152
153
154 /* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
155 HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9 iface, 
156                                 UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool,
157                                 IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
158     
159     IDirect3DVertexBuffer9Impl *object;
160     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
161     HRESULT hrc = D3D_OK;
162
163     /* Allocate the storage for the device */
164     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
165     if (NULL == object) {
166         FIXME("Allocation of memory failed\n");
167         *ppVertexBuffer = NULL;
168         return D3DERR_OUTOFVIDEOMEMORY;
169     }
170
171     object->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
172     object->ref = 1;
173     hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage, FVF, Pool, &(object->wineD3DVertexBuffer), pSharedHandle, (IUnknown *)object);
174     
175     if (hrc != D3D_OK) {
176         /* free up object */ 
177         FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
178         HeapFree(GetProcessHeap(), 0, object);
179         *ppVertexBuffer = NULL;
180     } else {
181         *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
182     }
183     return hrc;
184 }