2009-07-11 18:00:20 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright 2002 Raphael Junqueira
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-03-15 04:03:22 +01:00
|
|
|
#include "d3dx9_private.h"
|
2009-07-11 18:00:20 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
|
|
|
|
|
2011-03-30 12:51:40 +02:00
|
|
|
struct ID3DXBufferImpl
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-01-27 00:27:21 +01:00
|
|
|
ID3DXBuffer ID3DXBuffer_iface;
|
|
|
|
LONG ref;
|
|
|
|
|
2011-03-30 12:51:43 +02:00
|
|
|
void *buffer;
|
|
|
|
DWORD size;
|
2011-03-30 12:51:40 +02:00
|
|
|
};
|
2011-01-27 00:27:21 +01:00
|
|
|
|
2011-03-30 12:51:40 +02:00
|
|
|
static inline struct ID3DXBufferImpl *impl_from_ID3DXBuffer(ID3DXBuffer *iface)
|
2011-01-27 00:27:21 +01:00
|
|
|
{
|
2011-03-30 12:51:40 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct ID3DXBufferImpl, ID3DXBuffer_iface);
|
2011-01-27 00:27:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(ID3DXBuffer *iface, REFIID riid, void **ppobj)
|
|
|
|
{
|
2011-03-30 12:51:46 +02:00
|
|
|
TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), ppobj);
|
2009-07-11 18:00:20 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_ID3DXBuffer))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
2011-03-30 12:51:46 +02:00
|
|
|
*ppobj = iface;
|
2009-07-11 18:00:20 +02:00
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-30 12:51:46 +02:00
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
2009-07-11 18:00:20 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:27:21 +01:00
|
|
|
static ULONG WINAPI ID3DXBufferImpl_AddRef(ID3DXBuffer *iface)
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-03-30 12:51:40 +02:00
|
|
|
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
|
2009-07-11 18:00:20 +02:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2011-03-30 12:51:46 +02:00
|
|
|
TRACE("%p increasing refcount to %u\n", This, ref);
|
2009-07-11 18:00:20 +02:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:27:21 +01:00
|
|
|
static ULONG WINAPI ID3DXBufferImpl_Release(ID3DXBuffer *iface)
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-03-30 12:51:40 +02:00
|
|
|
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
|
2009-07-11 18:00:20 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2011-03-30 12:51:46 +02:00
|
|
|
TRACE("%p decreasing refcount to %u\n", This, ref);
|
2009-07-11 18:00:20 +02:00
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->buffer);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2011-03-30 12:51:46 +02:00
|
|
|
|
2009-07-11 18:00:20 +02:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2013-09-04 08:56:46 +02:00
|
|
|
static void * WINAPI ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer *iface)
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-03-30 12:51:40 +02:00
|
|
|
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
|
2011-03-30 12:51:46 +02:00
|
|
|
|
|
|
|
TRACE("iface %p\n", iface);
|
|
|
|
|
2009-07-11 18:00:20 +02:00
|
|
|
return This->buffer;
|
|
|
|
}
|
|
|
|
|
2011-01-27 00:27:21 +01:00
|
|
|
static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(ID3DXBuffer *iface)
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-03-30 12:51:40 +02:00
|
|
|
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
|
2011-03-30 12:51:46 +02:00
|
|
|
|
|
|
|
TRACE("iface %p\n", iface);
|
|
|
|
|
2011-03-30 12:51:43 +02:00
|
|
|
return This->size;
|
2009-07-11 18:00:20 +02:00
|
|
|
}
|
|
|
|
|
2011-03-30 12:51:43 +02:00
|
|
|
static const struct ID3DXBufferVtbl ID3DXBufferImpl_Vtbl =
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-03-30 12:51:43 +02:00
|
|
|
/* IUnknown methods */
|
2009-07-11 18:00:20 +02:00
|
|
|
ID3DXBufferImpl_QueryInterface,
|
|
|
|
ID3DXBufferImpl_AddRef,
|
|
|
|
ID3DXBufferImpl_Release,
|
2011-03-30 12:51:43 +02:00
|
|
|
/* ID3DXBuffer methods */
|
2009-07-11 18:00:20 +02:00
|
|
|
ID3DXBufferImpl_GetBufferPointer,
|
|
|
|
ID3DXBufferImpl_GetBufferSize
|
|
|
|
};
|
|
|
|
|
2011-03-30 12:51:49 +02:00
|
|
|
static HRESULT d3dx9_buffer_init(struct ID3DXBufferImpl *buffer, DWORD size)
|
|
|
|
{
|
|
|
|
buffer->ID3DXBuffer_iface.lpVtbl = &ID3DXBufferImpl_Vtbl;
|
|
|
|
buffer->ref = 1;
|
|
|
|
buffer->size = size;
|
|
|
|
|
|
|
|
buffer->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
|
|
|
if (!buffer->buffer)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate buffer memory\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-02 18:53:17 +01:00
|
|
|
HRESULT WINAPI D3DXCreateBuffer(DWORD size, ID3DXBuffer **buffer)
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-03-30 12:51:40 +02:00
|
|
|
struct ID3DXBufferImpl *object;
|
2011-03-30 12:51:49 +02:00
|
|
|
HRESULT hr;
|
2009-07-11 18:00:20 +02:00
|
|
|
|
2011-04-01 15:00:11 +02:00
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
WARN("Invalid buffer specified.\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2011-03-30 12:51:37 +02:00
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
2011-03-30 12:51:49 +02:00
|
|
|
if (!object)
|
2009-07-11 18:00:20 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2011-03-30 12:51:49 +02:00
|
|
|
|
|
|
|
hr = d3dx9_buffer_init(object, size);
|
|
|
|
if (FAILED(hr))
|
2009-07-11 18:00:20 +02:00
|
|
|
{
|
2011-03-30 12:51:49 +02:00
|
|
|
WARN("Failed to initialize buffer, hr %#x.\n", hr);
|
2009-07-11 18:00:20 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
2011-03-30 12:51:49 +02:00
|
|
|
return hr;
|
2009-07-11 18:00:20 +02:00
|
|
|
}
|
|
|
|
|
2011-03-30 12:51:43 +02:00
|
|
|
*buffer = &object->ID3DXBuffer_iface;
|
2011-03-30 12:51:49 +02:00
|
|
|
|
2016-01-15 10:08:59 +01:00
|
|
|
TRACE("Created ID3DXBuffer %p.\n", *buffer);
|
2011-03-30 12:51:49 +02:00
|
|
|
|
2009-07-11 18:00:20 +02:00
|
|
|
return D3D_OK;
|
|
|
|
}
|