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
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
;
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
);
59 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
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
);
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
);
83 HeapFree(GetProcessHeap(), 0, This
->buffer
);
84 HeapFree(GetProcessHeap(), 0, This
);
90 static LPVOID WINAPI
ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer
*iface
)
92 struct ID3DXBufferImpl
*This
= impl_from_ID3DXBuffer(iface
);
94 TRACE("iface %p\n", iface
);
99 static DWORD WINAPI
ID3DXBufferImpl_GetBufferSize(ID3DXBuffer
*iface
)
101 struct ID3DXBufferImpl
*This
= impl_from_ID3DXBuffer(iface
);
103 TRACE("iface %p\n", iface
);
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
;
125 buffer
->buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
128 ERR("Failed to allocate buffer memory\n");
129 return E_OUTOFMEMORY
;
135 HRESULT WINAPI
D3DXCreateBuffer(DWORD size
, LPD3DXBUFFER
*buffer
)
137 struct ID3DXBufferImpl
*object
;
142 WARN("Invalid buffer specified.\n");
143 return D3DERR_INVALIDCALL
;
146 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
149 ERR("Failed to allocate buffer memory\n");
150 return E_OUTOFMEMORY
;
153 hr
= d3dx9_buffer_init(object
, size
);
156 WARN("Failed to initialize buffer, hr %#x.\n", hr
);
157 HeapFree(GetProcessHeap(), 0, object
);
161 *buffer
= &object
->ID3DXBuffer_iface
;
163 TRACE("Created ID3DBuffer %p\n", *buffer
);