2012-12-25 10:42:01 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Christian Costa
|
|
|
|
*
|
|
|
|
* 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 "wine/debug.h"
|
|
|
|
|
|
|
|
#include "d3dx9.h"
|
|
|
|
#include "d3dx9xof.h"
|
2013-01-04 09:45:08 +01:00
|
|
|
#undef MAKE_DDHRESULT
|
|
|
|
#include "dxfile.h"
|
2012-12-25 10:42:01 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
|
|
|
|
|
2013-01-07 07:45:35 +01:00
|
|
|
static HRESULT error_dxfile_to_d3dxfile(HRESULT error)
|
2013-01-04 09:45:08 +01:00
|
|
|
{
|
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case DXFILEERR_BADFILETYPE:
|
|
|
|
return D3DXFERR_BADFILETYPE;
|
|
|
|
case DXFILEERR_BADFILEVERSION:
|
|
|
|
return D3DXFERR_BADFILEVERSION;
|
|
|
|
case DXFILEERR_BADFILEFLOATSIZE:
|
|
|
|
return D3DXFERR_BADFILEFLOATSIZE;
|
|
|
|
case DXFILEERR_PARSEERROR:
|
|
|
|
return D3DXFERR_PARSEERROR;
|
2013-05-16 01:09:01 +02:00
|
|
|
case DXFILEERR_BADVALUE:
|
|
|
|
return D3DXFERR_BADVALUE;
|
2013-01-04 09:45:08 +01:00
|
|
|
default:
|
|
|
|
FIXME("Cannot map error %#x\n", error);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-25 10:42:01 +01:00
|
|
|
typedef struct {
|
|
|
|
ID3DXFile ID3DXFile_iface;
|
|
|
|
LONG ref;
|
2013-01-04 09:45:08 +01:00
|
|
|
IDirectXFile *dxfile;
|
2012-12-25 10:42:01 +01:00
|
|
|
} ID3DXFileImpl;
|
|
|
|
|
2013-01-08 08:46:44 +01:00
|
|
|
typedef struct {
|
|
|
|
ID3DXFileEnumObject ID3DXFileEnumObject_iface;
|
|
|
|
LONG ref;
|
2013-01-09 10:22:33 +01:00
|
|
|
ULONG nb_children;
|
|
|
|
ID3DXFileData **children;
|
2013-01-08 08:46:44 +01:00
|
|
|
} ID3DXFileEnumObjectImpl;
|
2012-12-25 10:42:01 +01:00
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
typedef struct {
|
|
|
|
ID3DXFileData ID3DXFileData_iface;
|
|
|
|
LONG ref;
|
2013-01-21 08:41:02 +01:00
|
|
|
BOOL reference;
|
2013-01-09 10:22:33 +01:00
|
|
|
IDirectXFileData *dxfile_data;
|
2013-01-21 08:41:02 +01:00
|
|
|
ULONG nb_children;
|
|
|
|
ID3DXFileData **children;
|
2013-01-09 10:22:33 +01:00
|
|
|
} ID3DXFileDataImpl;
|
|
|
|
|
|
|
|
|
2012-12-25 10:42:01 +01:00
|
|
|
static inline ID3DXFileImpl* impl_from_ID3DXFile(ID3DXFile *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ID3DXFileImpl, ID3DXFile_iface);
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:46:44 +01:00
|
|
|
static inline ID3DXFileEnumObjectImpl* impl_from_ID3DXFileEnumObject(ID3DXFileEnumObject *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ID3DXFileEnumObjectImpl, ID3DXFileEnumObject_iface);
|
|
|
|
}
|
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
static inline ID3DXFileDataImpl* impl_from_ID3DXFileData(ID3DXFileData *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ID3DXFileDataImpl, ID3DXFileData_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_QueryInterface(ID3DXFileData *iface, REFIID riid, void **ret_iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_ID3DXFileData))
|
|
|
|
{
|
|
|
|
iface->lpVtbl->AddRef(iface);
|
|
|
|
*ret_iface = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s, %p), not found\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
*ret_iface = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ID3DXFileDataImpl_AddRef(ID3DXFileData *iface)
|
|
|
|
{
|
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ID3DXFileDataImpl_Release(ID3DXFileData *iface)
|
|
|
|
{
|
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
|
|
|
|
|
|
|
if (!ref)
|
|
|
|
{
|
2013-01-21 08:41:02 +01:00
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
for (i = 0; i < This->nb_children; i++)
|
|
|
|
(This->children[i])->lpVtbl->Release(This->children[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->children);
|
2013-01-09 10:22:33 +01:00
|
|
|
IDirectXFileData_Release(This->dxfile_data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*** ID3DXFileData methods ***/
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_GetEnum(ID3DXFileData *iface, ID3DXFileEnumObject **enum_object)
|
|
|
|
{
|
|
|
|
FIXME("(%p)->(%p): stub\n", iface, enum_object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_GetName(ID3DXFileData *iface, char *name, SIZE_T *size)
|
|
|
|
{
|
2013-01-14 10:20:54 +01:00
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
|
|
|
DWORD dxfile_size;
|
|
|
|
HRESULT ret;
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-14 10:20:54 +01:00
|
|
|
TRACE("(%p)->(%p, %p)\n", iface, name, size);
|
|
|
|
|
2013-05-16 01:09:01 +02:00
|
|
|
if (!size)
|
|
|
|
return D3DXFERR_BADVALUE;
|
2013-01-14 10:20:54 +01:00
|
|
|
|
|
|
|
dxfile_size = *size;
|
|
|
|
|
|
|
|
ret = IDirectXFileData_GetName(This->dxfile_data, name, &dxfile_size);
|
|
|
|
if (ret != DXFILE_OK)
|
|
|
|
return error_dxfile_to_d3dxfile(ret);
|
|
|
|
|
2013-05-16 01:09:01 +02:00
|
|
|
if (!dxfile_size)
|
|
|
|
{
|
|
|
|
/* Contrary to d3dxof, d3dx9_36 returns an empty string with a null byte when no name is available.
|
|
|
|
* If the input size is 0, it returns a length of 1 without touching the buffer */
|
|
|
|
dxfile_size = 1;
|
|
|
|
if (name && *size)
|
|
|
|
name[0] = 0;
|
|
|
|
}
|
|
|
|
|
2013-01-14 10:20:54 +01:00
|
|
|
*size = dxfile_size;
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_GetId(ID3DXFileData *iface, GUID *guid)
|
|
|
|
{
|
2013-01-14 10:21:03 +01:00
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
|
|
|
HRESULT ret;
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-14 10:21:03 +01:00
|
|
|
TRACE("(%p)->(%p)\n", iface, guid);
|
|
|
|
|
|
|
|
if (!guid)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
ret = IDirectXFileData_GetId(This->dxfile_data, guid);
|
|
|
|
if (ret != DXFILE_OK)
|
|
|
|
return error_dxfile_to_d3dxfile(ret);
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_Lock(ID3DXFileData *iface, SIZE_T *size, const void **data)
|
|
|
|
{
|
2013-01-18 08:49:17 +01:00
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
|
|
|
DWORD dxfile_size;
|
|
|
|
HRESULT ret;
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-18 08:49:17 +01:00
|
|
|
TRACE("(%p)->(%p, %p)\n", iface, size, data);
|
|
|
|
|
|
|
|
if (!size || !data)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
ret = IDirectXFileData_GetData(This->dxfile_data, NULL, &dxfile_size, (void**)data);
|
|
|
|
if (ret != DXFILE_OK)
|
|
|
|
return error_dxfile_to_d3dxfile(ret);
|
|
|
|
|
|
|
|
*size = dxfile_size;
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_Unlock(ID3DXFileData *iface)
|
|
|
|
{
|
2013-01-18 08:49:17 +01:00
|
|
|
TRACE("(%p)->()\n", iface);
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-18 08:49:17 +01:00
|
|
|
/* Nothing to do */
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_GetType(ID3DXFileData *iface, GUID *guid)
|
|
|
|
{
|
2013-01-10 09:37:01 +01:00
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
|
|
|
const GUID *dxfile_guid;
|
|
|
|
HRESULT ret;
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-10 09:37:01 +01:00
|
|
|
TRACE("(%p)->(%p)\n", iface, guid);
|
|
|
|
|
|
|
|
ret = IDirectXFileData_GetType(This->dxfile_data, &dxfile_guid);
|
|
|
|
if (ret != DXFILE_OK)
|
|
|
|
return error_dxfile_to_d3dxfile(ret);
|
|
|
|
|
|
|
|
*guid = *dxfile_guid;
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL WINAPI ID3DXFileDataImpl_IsReference(ID3DXFileData *iface)
|
|
|
|
{
|
2013-01-22 08:36:28 +01:00
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-22 08:36:28 +01:00
|
|
|
TRACE("(%p)->()\n", iface);
|
|
|
|
|
|
|
|
return This->reference;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_GetChildren(ID3DXFileData *iface, SIZE_T *children)
|
|
|
|
{
|
2013-01-22 08:36:19 +01:00
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-22 08:36:19 +01:00
|
|
|
TRACE("(%p)->(%p)\n", iface, children);
|
|
|
|
|
|
|
|
if (!children)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*children = This->nb_children;
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileDataImpl_GetChild(ID3DXFileData *iface, SIZE_T id, ID3DXFileData **object)
|
|
|
|
{
|
2013-01-22 08:36:19 +01:00
|
|
|
ID3DXFileDataImpl *This = impl_from_ID3DXFileData(iface);
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-22 08:36:19 +01:00
|
|
|
TRACE("(%p)->(%lu, %p)\n", iface, id, object);
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*object = This->children[id];
|
|
|
|
(*object)->lpVtbl->AddRef(*object);
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const ID3DXFileDataVtbl ID3DXFileData_Vtbl =
|
|
|
|
{
|
|
|
|
ID3DXFileDataImpl_QueryInterface,
|
|
|
|
ID3DXFileDataImpl_AddRef,
|
|
|
|
ID3DXFileDataImpl_Release,
|
|
|
|
ID3DXFileDataImpl_GetEnum,
|
|
|
|
ID3DXFileDataImpl_GetName,
|
|
|
|
ID3DXFileDataImpl_GetId,
|
|
|
|
ID3DXFileDataImpl_Lock,
|
|
|
|
ID3DXFileDataImpl_Unlock,
|
|
|
|
ID3DXFileDataImpl_GetType,
|
|
|
|
ID3DXFileDataImpl_IsReference,
|
|
|
|
ID3DXFileDataImpl_GetChildren,
|
|
|
|
ID3DXFileDataImpl_GetChild
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-21 08:41:02 +01:00
|
|
|
static HRESULT ID3DXFileDataImpl_Create(IDirectXFileObject *dxfile_object, ID3DXFileData **ret_iface)
|
2013-01-09 10:22:33 +01:00
|
|
|
{
|
|
|
|
ID3DXFileDataImpl *object;
|
2013-01-21 08:41:02 +01:00
|
|
|
IDirectXFileObject *data_object;
|
|
|
|
HRESULT ret;
|
2013-01-09 10:22:33 +01:00
|
|
|
|
2013-01-21 08:41:02 +01:00
|
|
|
TRACE("(%p, %p)\n", dxfile_object, ret_iface);
|
2013-01-09 10:22:33 +01:00
|
|
|
|
|
|
|
*ret_iface = NULL;
|
|
|
|
|
2013-01-21 08:41:02 +01:00
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
2013-01-09 10:22:33 +01:00
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->ID3DXFileData_iface.lpVtbl = &ID3DXFileData_Vtbl;
|
|
|
|
object->ref = 1;
|
2013-01-21 08:41:02 +01:00
|
|
|
|
|
|
|
ret = IDirectXFileObject_QueryInterface(dxfile_object, &IID_IDirectXFileData, (void **)&object->dxfile_data);
|
|
|
|
if (FAILED(ret))
|
|
|
|
{
|
|
|
|
IDirectXFileDataReference *reference;
|
|
|
|
|
|
|
|
ret = IDirectXFileObject_QueryInterface(dxfile_object, &IID_IDirectXFileDataReference, (void **)&reference);
|
|
|
|
if (SUCCEEDED(ret))
|
|
|
|
{
|
|
|
|
ret = IDirectXFileDataReference_Resolve(reference, &object->dxfile_data);
|
|
|
|
if (FAILED(ret))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
2013-01-22 08:36:28 +01:00
|
|
|
object->reference = TRUE;
|
2013-01-21 08:41:02 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Don't known what to do with binary object\n");
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (SUCCEEDED(ret = IDirectXFileData_GetNextObject(object->dxfile_data, &data_object)))
|
|
|
|
{
|
|
|
|
if (object->children)
|
|
|
|
object->children = HeapReAlloc(GetProcessHeap(), 0, object->children, sizeof(ID3DXFileData*) * (object->nb_children + 1));
|
|
|
|
else
|
|
|
|
object->children = HeapAlloc(GetProcessHeap(), 0, sizeof(ID3DXFileData*));
|
|
|
|
if (!object->children)
|
|
|
|
{
|
|
|
|
ret = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ret = ID3DXFileDataImpl_Create(data_object, &object->children[object->nb_children]);
|
|
|
|
if (ret != S_OK)
|
|
|
|
break;
|
|
|
|
object->nb_children++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != DXFILEERR_NOMOREOBJECTS)
|
|
|
|
{
|
|
|
|
(&object->ID3DXFileData_iface)->lpVtbl->Release(&object->ID3DXFileData_iface);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Found %u children\n", object->nb_children);
|
2013-01-09 10:22:33 +01:00
|
|
|
|
|
|
|
*ret_iface = &object->ID3DXFileData_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-08 08:46:44 +01:00
|
|
|
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileEnumObjectImpl_QueryInterface(ID3DXFileEnumObject *iface, REFIID riid, void **ret_iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_ID3DXFileEnumObject))
|
|
|
|
{
|
|
|
|
iface->lpVtbl->AddRef(iface);
|
|
|
|
*ret_iface = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s, %p), not found\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
*ret_iface = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ID3DXFileEnumObjectImpl_AddRef(ID3DXFileEnumObject *iface)
|
|
|
|
{
|
|
|
|
ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2013-01-08 08:46:44 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ID3DXFileEnumObjectImpl_Release(ID3DXFileEnumObject *iface)
|
|
|
|
{
|
|
|
|
ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2013-01-08 08:46:44 +01:00
|
|
|
|
|
|
|
if (!ref)
|
2013-01-09 10:22:33 +01:00
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
for (i = 0; i < This->nb_children; i++)
|
|
|
|
(This->children[i])->lpVtbl->Release(This->children[i]);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->children);
|
2013-01-08 08:46:44 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2013-01-09 10:22:33 +01:00
|
|
|
}
|
2013-01-08 08:46:44 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*** ID3DXFileEnumObject methods ***/
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetFile(ID3DXFileEnumObject *iface, ID3DXFile **file)
|
|
|
|
{
|
|
|
|
FIXME("(%p)->(%p): stub\n", iface, file);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetChildren(ID3DXFileEnumObject *iface, SIZE_T *children)
|
|
|
|
{
|
2013-01-10 09:36:53 +01:00
|
|
|
ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
|
2013-01-08 08:46:44 +01:00
|
|
|
|
2013-01-10 09:36:53 +01:00
|
|
|
TRACE("(%p)->(%p)\n", iface, children);
|
|
|
|
|
|
|
|
if (!children)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*children = This->nb_children;
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-08 08:46:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetChild(ID3DXFileEnumObject *iface, SIZE_T id, ID3DXFileData **object)
|
|
|
|
{
|
2013-01-10 09:36:53 +01:00
|
|
|
ID3DXFileEnumObjectImpl *This = impl_from_ID3DXFileEnumObject(iface);
|
2013-01-08 08:46:44 +01:00
|
|
|
|
2013-01-10 09:36:53 +01:00
|
|
|
TRACE("(%p)->(%lu, %p)\n", iface, id, object);
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*object = This->children[id];
|
|
|
|
(*object)->lpVtbl->AddRef(*object);
|
|
|
|
|
|
|
|
return S_OK;
|
2013-01-08 08:46:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetDataObjectById(ID3DXFileEnumObject *iface, REFGUID guid, ID3DXFileData **object)
|
|
|
|
{
|
|
|
|
FIXME("(%p)->(%s, %p): stub\n", iface, debugstr_guid(guid), object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileEnumObjectImpl_GetDataObjectByName(ID3DXFileEnumObject *iface, const char *name, ID3DXFileData **object)
|
|
|
|
{
|
|
|
|
FIXME("(%p)->(%s, %p): stub\n", iface, debugstr_a(name), object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const ID3DXFileEnumObjectVtbl ID3DXFileEnumObject_Vtbl =
|
|
|
|
{
|
|
|
|
ID3DXFileEnumObjectImpl_QueryInterface,
|
|
|
|
ID3DXFileEnumObjectImpl_AddRef,
|
|
|
|
ID3DXFileEnumObjectImpl_Release,
|
|
|
|
ID3DXFileEnumObjectImpl_GetFile,
|
|
|
|
ID3DXFileEnumObjectImpl_GetChildren,
|
|
|
|
ID3DXFileEnumObjectImpl_GetChild,
|
|
|
|
ID3DXFileEnumObjectImpl_GetDataObjectById,
|
|
|
|
ID3DXFileEnumObjectImpl_GetDataObjectByName
|
|
|
|
};
|
|
|
|
|
2012-12-25 10:42:01 +01:00
|
|
|
|
|
|
|
/*** IUnknown methods ***/
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileImpl_QueryInterface(ID3DXFile *iface, REFIID riid, void **ret_iface)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_ID3DXFile))
|
|
|
|
{
|
|
|
|
iface->lpVtbl->AddRef(iface);
|
|
|
|
*ret_iface = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s, %p), not found\n", iface, debugstr_guid(riid), ret_iface);
|
|
|
|
*ret_iface = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI ID3DXFileImpl_AddRef(ID3DXFile *iface)
|
|
|
|
{
|
|
|
|
ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2012-12-25 10:42:01 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ULONG WINAPI ID3DXFileImpl_Release(ID3DXFile *iface)
|
|
|
|
{
|
|
|
|
ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2012-12-25 10:42:01 +01:00
|
|
|
|
|
|
|
if (!ref)
|
2013-01-04 09:45:08 +01:00
|
|
|
{
|
|
|
|
IDirectXFile_Release(This->dxfile);
|
2012-12-25 10:42:01 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2013-01-04 09:45:08 +01:00
|
|
|
}
|
2012-12-25 10:42:01 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*** ID3DXFile methods ***/
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileImpl_CreateEnumObject(ID3DXFile *iface, const void *source, D3DXF_FILELOADOPTIONS options, ID3DXFileEnumObject **enum_object)
|
|
|
|
{
|
2013-01-09 10:22:33 +01:00
|
|
|
ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
|
2013-01-08 08:46:44 +01:00
|
|
|
ID3DXFileEnumObjectImpl *object;
|
2013-01-09 10:22:33 +01:00
|
|
|
IDirectXFileEnumObject *dxfile_enum_object;
|
|
|
|
void *dxfile_source;
|
|
|
|
DXFILELOADOPTIONS dxfile_options;
|
|
|
|
DXFILELOADRESOURCE dxfile_resource;
|
|
|
|
DXFILELOADMEMORY dxfile_memory;
|
|
|
|
IDirectXFileData *data_object;
|
|
|
|
HRESULT ret;
|
2012-12-25 10:42:01 +01:00
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
TRACE("(%p)->(%p, %x, %p)\n", iface, source, options, enum_object);
|
2013-01-08 08:46:44 +01:00
|
|
|
|
|
|
|
if (!enum_object)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*enum_object = NULL;
|
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
if (options == D3DXF_FILELOAD_FROMFILE)
|
|
|
|
{
|
|
|
|
dxfile_source = (void*)source;
|
|
|
|
dxfile_options = DXFILELOAD_FROMFILE;
|
|
|
|
}
|
|
|
|
else if (options == D3DXF_FILELOAD_FROMRESOURCE)
|
|
|
|
{
|
|
|
|
D3DXF_FILELOADRESOURCE *resource = (D3DXF_FILELOADRESOURCE*)source;
|
|
|
|
|
|
|
|
dxfile_resource.hModule = resource->hModule;
|
|
|
|
dxfile_resource.lpName = resource->lpName;
|
|
|
|
dxfile_resource.lpType = resource->lpType;
|
|
|
|
dxfile_source = &dxfile_resource;
|
|
|
|
dxfile_options = DXFILELOAD_FROMRESOURCE;
|
|
|
|
}
|
|
|
|
else if (options == D3DXF_FILELOAD_FROMMEMORY)
|
|
|
|
{
|
|
|
|
D3DXF_FILELOADMEMORY *memory = (D3DXF_FILELOADMEMORY*)source;
|
|
|
|
|
|
|
|
dxfile_memory.lpMemory = memory->lpMemory;
|
|
|
|
dxfile_memory.dSize = memory->dSize;
|
|
|
|
dxfile_source = &dxfile_memory;
|
|
|
|
dxfile_options = DXFILELOAD_FROMMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("Source type %u is not handled yet\n", options);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2013-01-18 08:49:09 +01:00
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
2013-01-08 08:46:44 +01:00
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
object->ID3DXFileEnumObject_iface.lpVtbl = &ID3DXFileEnumObject_Vtbl;
|
|
|
|
object->ref = 1;
|
|
|
|
|
2013-01-09 10:22:33 +01:00
|
|
|
ret = IDirectXFile_CreateEnumObject(This->dxfile, dxfile_source, dxfile_options, &dxfile_enum_object);
|
|
|
|
|
|
|
|
if (ret != S_OK)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill enum object with top level data objects */
|
|
|
|
while (SUCCEEDED(ret = IDirectXFileEnumObject_GetNextDataObject(dxfile_enum_object, &data_object)))
|
|
|
|
{
|
|
|
|
if (object->children)
|
|
|
|
object->children = HeapReAlloc(GetProcessHeap(), 0, object->children, sizeof(*object->children) * (object->nb_children + 1));
|
|
|
|
else
|
|
|
|
object->children = HeapAlloc(GetProcessHeap(), 0, sizeof(*object->children));
|
|
|
|
if (!object->children)
|
|
|
|
{
|
|
|
|
ret = E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-21 08:41:02 +01:00
|
|
|
ret = ID3DXFileDataImpl_Create((IDirectXFileObject*)data_object, &object->children[object->nb_children]);
|
2013-01-09 10:22:33 +01:00
|
|
|
if (ret != S_OK)
|
|
|
|
break;
|
|
|
|
object->nb_children++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDirectXFileEnumObject_Release(dxfile_enum_object);
|
|
|
|
|
|
|
|
if (ret != DXFILEERR_NOMOREOBJECTS)
|
|
|
|
WARN("Cannot get all top level data objects\n");
|
|
|
|
|
|
|
|
TRACE("Found %u children\n", object->nb_children);
|
|
|
|
|
2013-01-08 08:46:44 +01:00
|
|
|
*enum_object = &object->ID3DXFileEnumObject_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
2012-12-25 10:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileImpl_CreateSaveObject(ID3DXFile *iface, const void *data, D3DXF_FILESAVEOPTIONS options, D3DXF_FILEFORMAT format, ID3DXFileSaveObject **save_object)
|
|
|
|
{
|
|
|
|
FIXME("(%p)->(%p, %x, %u, %p): stub\n", iface, data, options, format, save_object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileImpl_RegisterTemplates(ID3DXFile *iface, const void *data, SIZE_T size)
|
|
|
|
{
|
2013-01-04 09:45:08 +01:00
|
|
|
ID3DXFileImpl *This = impl_from_ID3DXFile(iface);
|
|
|
|
HRESULT ret;
|
2012-12-25 10:42:01 +01:00
|
|
|
|
2013-01-04 09:45:08 +01:00
|
|
|
TRACE("(%p)->(%p, %lu)\n", iface, data, size);
|
|
|
|
|
|
|
|
ret = IDirectXFile_RegisterTemplates(This->dxfile, (void*)data, size);
|
|
|
|
if (ret != DXFILE_OK)
|
|
|
|
{
|
|
|
|
WARN("Error %#x\n", ret);
|
|
|
|
return error_dxfile_to_d3dxfile(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2012-12-25 10:42:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static HRESULT WINAPI ID3DXFileImpl_RegisterEnumTemplates(ID3DXFile *iface, ID3DXFileEnumObject *enum_object)
|
|
|
|
{
|
|
|
|
FIXME("(%p)->(%p): stub\n", iface, enum_object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const ID3DXFileVtbl ID3DXFile_Vtbl =
|
|
|
|
{
|
|
|
|
ID3DXFileImpl_QueryInterface,
|
|
|
|
ID3DXFileImpl_AddRef,
|
|
|
|
ID3DXFileImpl_Release,
|
|
|
|
ID3DXFileImpl_CreateEnumObject,
|
|
|
|
ID3DXFileImpl_CreateSaveObject,
|
|
|
|
ID3DXFileImpl_RegisterTemplates,
|
|
|
|
ID3DXFileImpl_RegisterEnumTemplates
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT WINAPI D3DXFileCreate(ID3DXFile **d3dxfile)
|
|
|
|
{
|
|
|
|
ID3DXFileImpl *object;
|
2013-01-04 09:45:08 +01:00
|
|
|
HRESULT ret;
|
2012-12-25 10:42:01 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", d3dxfile);
|
|
|
|
|
|
|
|
if (!d3dxfile)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*d3dxfile = NULL;
|
|
|
|
|
|
|
|
object = HeapAlloc(GetProcessHeap(), 0, sizeof(*object));
|
|
|
|
if (!object)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2013-01-04 09:45:08 +01:00
|
|
|
ret = DirectXFileCreate(&object->dxfile);
|
|
|
|
if (ret != S_OK)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
if (ret == E_OUTOFMEMORY)
|
|
|
|
return ret;
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2012-12-25 10:42:01 +01:00
|
|
|
object->ID3DXFile_iface.lpVtbl = &ID3DXFile_Vtbl;
|
|
|
|
object->ref = 1;
|
|
|
|
|
|
|
|
*d3dxfile = &object->ID3DXFile_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|