Sweden-Number/dlls/d3dx9_36/core.c

135 lines
3.6 KiB
C
Raw Normal View History

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
*/
#include <stdarg.h>
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "wine/debug.h"
#include "wine/unicode.h"
#include "d3dx9_36_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
struct ID3DXBufferImpl
2009-07-11 18:00:20 +02:00
{
ID3DXBuffer ID3DXBuffer_iface;
LONG ref;
2011-03-30 12:51:43 +02:00
void *buffer;
DWORD size;
};
static inline struct ID3DXBufferImpl *impl_from_ID3DXBuffer(ID3DXBuffer *iface)
{
return CONTAINING_RECORD(iface, struct ID3DXBufferImpl, ID3DXBuffer_iface);
}
static HRESULT WINAPI ID3DXBufferImpl_QueryInterface(ID3DXBuffer *iface, REFIID riid, void **ppobj)
{
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
2009-07-11 18:00:20 +02:00
if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_ID3DXBuffer))
{
IUnknown_AddRef(iface);
*ppobj = This;
return D3D_OK;
}
WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
return E_NOINTERFACE;
}
static ULONG WINAPI ID3DXBufferImpl_AddRef(ID3DXBuffer *iface)
2009-07-11 18:00:20 +02:00
{
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
2009-07-11 18:00:20 +02:00
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("(%p) : AddRef from %d\n", This, ref - 1);
return ref;
}
static ULONG WINAPI ID3DXBufferImpl_Release(ID3DXBuffer *iface)
2009-07-11 18:00:20 +02:00
{
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
2009-07-11 18:00:20 +02:00
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) : ReleaseRef to %d\n", This, ref);
if (ref == 0)
{
HeapFree(GetProcessHeap(), 0, This->buffer);
HeapFree(GetProcessHeap(), 0, This);
}
return ref;
}
static LPVOID WINAPI ID3DXBufferImpl_GetBufferPointer(ID3DXBuffer *iface)
2009-07-11 18:00:20 +02:00
{
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(iface);
2009-07-11 18:00:20 +02:00
return This->buffer;
}
static DWORD WINAPI ID3DXBufferImpl_GetBufferSize(ID3DXBuffer *iface)
2009-07-11 18:00:20 +02:00
{
struct ID3DXBufferImpl *This = impl_from_ID3DXBuffer(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:43 +02:00
HRESULT WINAPI D3DXCreateBuffer(DWORD size, LPD3DXBUFFER *buffer)
2009-07-11 18:00:20 +02:00
{
struct ID3DXBufferImpl *object;
2009-07-11 18:00:20 +02:00
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2009-07-11 18:00:20 +02:00
if (object == NULL)
{
2011-03-30 12:51:43 +02:00
*buffer = NULL;
2009-07-11 18:00:20 +02:00
return E_OUTOFMEMORY;
}
2011-03-30 12:51:43 +02:00
object->ID3DXBuffer_iface.lpVtbl = &ID3DXBufferImpl_Vtbl;
2009-07-11 18:00:20 +02:00
object->ref = 1;
2011-03-30 12:51:43 +02:00
object->size = size;
object->buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
2009-07-11 18:00:20 +02:00
if (object->buffer == NULL)
{
HeapFree(GetProcessHeap(), 0, object);
2011-03-30 12:51:43 +02:00
*buffer = NULL;
2009-07-11 18:00:20 +02:00
return E_OUTOFMEMORY;
}
2011-03-30 12:51:43 +02:00
*buffer = &object->ID3DXBuffer_iface;
2009-07-11 18:00:20 +02:00
return D3D_OK;
}