dsound: clean up capture interface and prepare for mmdevapi (v2)
[wine/multimedia.git] / dlls / d3dx9_36 / core.c
blob894797066d10b71ab78f6dbfc434d265836a942e
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 LPVOID 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, LPD3DXBUFFER *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)
149 ERR("Failed to allocate buffer memory\n");
150 return E_OUTOFMEMORY;
153 hr = d3dx9_buffer_init(object, size);
154 if (FAILED(hr))
156 WARN("Failed to initialize buffer, hr %#x.\n", hr);
157 HeapFree(GetProcessHeap(), 0, object);
158 return hr;
161 *buffer = &object->ID3DXBuffer_iface;
163 TRACE("Created ID3DBuffer %p\n", *buffer);
165 return D3D_OK;