comdlg32/tests: Use BOOL type where appropriate.
[wine.git] / dlls / d3dx9_36 / core.c
blob53e9531f451ba6d07a8a217e1f719654ec0cfc48
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 struct ID3DXBufferImpl
35 ID3DXBuffer ID3DXBuffer_iface;
36 LONG ref;
38 void *buffer;
39 DWORD size;
42 static inline struct ID3DXBufferImpl *impl_from_ID3DXBuffer(ID3DXBuffer *iface)
44 return CONTAINING_RECORD(iface, struct ID3DXBufferImpl, ID3DXBuffer_iface);
47 static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(ID3DXBuffer *iface, REFIID riid, void **ppobj)
49 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), ppobj);
51 if (IsEqualGUID(riid, &IID_IUnknown)
52 || IsEqualGUID(riid, &IID_ID3DXBuffer))
54 IUnknown_AddRef(iface);
55 *ppobj = iface;
56 return D3D_OK;
59 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
61 return E_NOINTERFACE;
64 static ULONG WINAPI ID3DXBufferImpl_AddRef(ID3DXBuffer *iface)
66 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
67 ULONG ref = InterlockedIncrement(&This->ref);
69 TRACE("%p increasing refcount to %u\n", This, ref);
71 return ref;
74 static ULONG WINAPI ID3DXBufferImpl_Release(ID3DXBuffer *iface)
76 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
77 ULONG ref = InterlockedDecrement(&This->ref);
79 TRACE("%p decreasing refcount to %u\n", This, ref);
81 if (ref == 0)
83 HeapFree(GetProcessHeap(), 0, This->buffer);
84 HeapFree(GetProcessHeap(), 0, This);
87 return ref;
90 static void * WINAPI ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer *iface)
92 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
94 TRACE("iface %p\n", iface);
96 return This->buffer;
99 static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(ID3DXBuffer *iface)
101 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
103 TRACE("iface %p\n", iface);
105 return This->size;
108 static const struct ID3DXBufferVtbl ID3DXBufferImpl_Vtbl =
110 /* IUnknown methods */
111 ID3DXBufferImpl_QueryInterface,
112 ID3DXBufferImpl_AddRef,
113 ID3DXBufferImpl_Release,
114 /* ID3DXBuffer methods */
115 ID3DXBufferImpl_GetBufferPointer,
116 ID3DXBufferImpl_GetBufferSize
119 static HRESULT d3dx9_buffer_init(struct ID3DXBufferImpl *buffer, DWORD size)
121 buffer->ID3DXBuffer_iface.lpVtbl = &ID3DXBufferImpl_Vtbl;
122 buffer->ref = 1;
123 buffer->size = size;
125 buffer->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
126 if (!buffer->buffer)
128 ERR("Failed to allocate buffer memory\n");
129 return E_OUTOFMEMORY;
132 return D3D_OK;
135 HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
137 struct ID3DXBufferImpl *object;
138 HRESULT hr;
140 if (!buffer)
142 WARN("Invalid buffer specified.\n");
143 return D3DERR_INVALIDCALL;
146 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
147 if (!object)
148 return E_OUTOFMEMORY;
150 hr = d3dx9_buffer_init(object, size);
151 if (FAILED(hr))
153 WARN("Failed to initialize buffer, hr %#x.\n", hr);
154 HeapFree(GetProcessHeap(), 0, object);
155 return hr;
158 *buffer = &object->ID3DXBuffer_iface;
160 TRACE("Created ID3DBuffer %p\n", *buffer);
162 return D3D_OK;