winebuild: Don't remove stdcall decorations on non-x86.
[wine.git] / dlls / d3dx9_36 / core.c
blob6990fbda957c4e12a2b67cb1549a76b46e0bf28d
1 /*
3 * Copyright 2002 Raphael Junqueira
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
29 #include "d3dx9_36_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
33 typedef struct ID3DXBufferImpl
35 ID3DXBuffer ID3DXBuffer_iface;
36 LONG ref;
38 DWORD *buffer;
39 DWORD bufferSize;
40 } ID3DXBufferImpl;
42 static inline ID3DXBufferImpl *impl_from_ID3DXBuffer(ID3DXBuffer *iface)
44 return CONTAINING_RECORD(iface, ID3DXBufferImpl, ID3DXBuffer_iface);
47 static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(ID3DXBuffer *iface, REFIID riid, void **ppobj)
49 ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
51 if (IsEqualGUID(riid, &IID_IUnknown)
52 || IsEqualGUID(riid, &IID_ID3DXBuffer))
54 IUnknown_AddRef(iface);
55 *ppobj = This;
56 return D3D_OK;
59 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
60 return E_NOINTERFACE;
63 static ULONG WINAPI ID3DXBufferImpl_AddRef(ID3DXBuffer *iface)
65 ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
66 ULONG ref = InterlockedIncrement(&This->ref);
68 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
70 return ref;
73 static ULONG WINAPI ID3DXBufferImpl_Release(ID3DXBuffer *iface)
75 ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
76 ULONG ref = InterlockedDecrement(&This->ref);
78 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
80 if (ref == 0)
82 HeapFree(GetProcessHeap(), 0, This->buffer);
83 HeapFree(GetProcessHeap(), 0, This);
85 return ref;
88 static LPVOID WINAPI ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer *iface)
90 ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
91 return This->buffer;
94 static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(ID3DXBuffer *iface)
96 ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
97 return This->bufferSize;
100 const ID3DXBufferVtbl D3DXBuffer_Vtbl =
102 ID3DXBufferImpl_QueryInterface,
103 ID3DXBufferImpl_AddRef,
104 ID3DXBufferImpl_Release,
105 ID3DXBufferImpl_GetBufferPointer,
106 ID3DXBufferImpl_GetBufferSize
109 HRESULT WINAPI D3DXCreateBuffer(DWORD NumBytes, LPD3DXBUFFER* ppBuffer)
111 ID3DXBufferImpl *object;
113 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXBufferImpl));
114 if (object == NULL)
116 *ppBuffer = NULL;
117 return E_OUTOFMEMORY;
119 object->ID3DXBuffer_iface.lpVtbl = &D3DXBuffer_Vtbl;
120 object->ref = 1;
121 object->bufferSize = NumBytes;
122 object->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, NumBytes);
123 if (object->buffer == NULL)
125 HeapFree(GetProcessHeap(), 0, object);
126 *ppBuffer = NULL;
127 return E_OUTOFMEMORY;
130 *ppBuffer = &object->ID3DXBuffer_iface;
131 return D3D_OK;