netapi32: Remove DECLSPEC_HIDDEN usage.
[wine.git] / dlls / d3dx9_36 / core.c
blob37f9d9aab8dbea488d2dcdc0f1c72ac5a9f235f5
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
21 #include "d3dx9_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
25 struct ID3DXBufferImpl
27 ID3DXBuffer ID3DXBuffer_iface;
28 LONG ref;
30 void *buffer;
31 DWORD size;
34 static inline struct ID3DXBufferImpl *impl_from_ID3DXBuffer(ID3DXBuffer *iface)
36 return CONTAINING_RECORD(iface, struct ID3DXBufferImpl, ID3DXBuffer_iface);
39 static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(ID3DXBuffer *iface, REFIID riid, void **ppobj)
41 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), ppobj);
43 if (IsEqualGUID(riid, &IID_IUnknown)
44 || IsEqualGUID(riid, &IID_ID3DXBuffer))
46 IUnknown_AddRef(iface);
47 *ppobj = iface;
48 return D3D_OK;
51 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
53 return E_NOINTERFACE;
56 static ULONG WINAPI ID3DXBufferImpl_AddRef(ID3DXBuffer *iface)
58 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
59 ULONG ref = InterlockedIncrement(&This->ref);
61 TRACE("%p increasing refcount to %lu.\n", This, ref);
63 return ref;
66 static ULONG WINAPI ID3DXBufferImpl_Release(ID3DXBuffer *iface)
68 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
69 ULONG ref = InterlockedDecrement(&This->ref);
71 TRACE("%p decreasing refcount to %lu.\n", This, ref);
73 if (ref == 0)
75 HeapFree(GetProcessHeap(), 0, This->buffer);
76 HeapFree(GetProcessHeap(), 0, This);
79 return ref;
82 static void * WINAPI ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer *iface)
84 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
86 TRACE("iface %p\n", iface);
88 return This->buffer;
91 static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(ID3DXBuffer *iface)
93 struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
95 TRACE("iface %p\n", iface);
97 return This->size;
100 static const struct ID3DXBufferVtbl ID3DXBufferImpl_Vtbl =
102 /* IUnknown methods */
103 ID3DXBufferImpl_QueryInterface,
104 ID3DXBufferImpl_AddRef,
105 ID3DXBufferImpl_Release,
106 /* ID3DXBuffer methods */
107 ID3DXBufferImpl_GetBufferPointer,
108 ID3DXBufferImpl_GetBufferSize
111 static HRESULT d3dx9_buffer_init(struct ID3DXBufferImpl *buffer, DWORD size)
113 buffer->ID3DXBuffer_iface.lpVtbl = &ID3DXBufferImpl_Vtbl;
114 buffer->ref = 1;
115 buffer->size = size;
117 buffer->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
118 if (!buffer->buffer)
120 ERR("Failed to allocate buffer memory\n");
121 return E_OUTOFMEMORY;
124 return D3D_OK;
127 HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
129 struct ID3DXBufferImpl *object;
130 HRESULT hr;
132 TRACE("size %lu, buffer %p.\n", size, buffer);
134 if (!buffer)
136 WARN("Invalid buffer specified.\n");
137 return D3DERR_INVALIDCALL;
140 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
141 if (!object)
142 return E_OUTOFMEMORY;
144 hr = d3dx9_buffer_init(object, size);
145 if (FAILED(hr))
147 WARN("Failed to initialize buffer, hr %#lx.\n", hr);
148 HeapFree(GetProcessHeap(), 0, object);
149 return hr;
152 *buffer = &object->ID3DXBuffer_iface;
154 TRACE("Created ID3DXBuffer %p.\n", *buffer);
156 return D3D_OK;