2004-05-18 02:54:12 +02:00
|
|
|
/*
|
2004-05-27 04:25:13 +02:00
|
|
|
* Copyright 2004 Ivan Leo Puoti
|
2010-01-07 22:43:25 +01:00
|
|
|
* Copyright 2010 Christian Costa
|
2004-05-18 02:54:12 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-05-18 02:54:12 +02:00
|
|
|
*/
|
|
|
|
|
2016-11-10 16:17:41 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
2016-03-03 09:10:21 +01:00
|
|
|
|
2014-04-24 12:18:01 +02:00
|
|
|
#include "initguid.h"
|
2016-03-03 09:10:21 +01:00
|
|
|
#include "d3drm_private.h"
|
2006-03-21 16:18:24 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllMain (D3DRM.@)
|
|
|
|
*/
|
2013-09-09 10:26:21 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
|
2006-03-21 16:18:24 +01:00
|
|
|
{
|
|
|
|
switch(reason)
|
|
|
|
{
|
|
|
|
case DLL_WINE_PREATTACH:
|
|
|
|
return FALSE; /* prefer native version */
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls( inst );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
2016-03-03 09:10:21 +01:00
|
|
|
|
2017-06-06 13:10:34 +02:00
|
|
|
void d3drm_object_init(struct d3drm_object *object, const char *classname)
|
2016-03-03 09:10:21 +01:00
|
|
|
{
|
|
|
|
object->ref = 1;
|
|
|
|
object->appdata = 0;
|
|
|
|
list_init(&object->destroy_callbacks);
|
2017-06-06 13:10:34 +02:00
|
|
|
object->classname = classname;
|
2017-06-21 14:39:30 +02:00
|
|
|
object->name = NULL;
|
2016-03-03 09:10:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct destroy_callback
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
D3DRMOBJECTCALLBACK cb;
|
|
|
|
void *ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
|
|
|
|
{
|
|
|
|
struct destroy_callback *callback;
|
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
return D3DRMERR_BADVALUE;
|
|
|
|
|
|
|
|
callback = HeapAlloc(GetProcessHeap(), 0, sizeof(*callback));
|
|
|
|
if (!callback)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
callback->cb = cb;
|
|
|
|
callback->ctx = ctx;
|
|
|
|
|
|
|
|
list_add_head(&object->destroy_callbacks, &callback->entry);
|
|
|
|
return D3DRM_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
|
|
|
|
{
|
2016-03-04 05:20:18 +01:00
|
|
|
struct destroy_callback *callback;
|
2016-03-03 09:10:21 +01:00
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
return D3DRMERR_BADVALUE;
|
|
|
|
|
2016-03-04 05:20:18 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(callback, &object->destroy_callbacks, struct destroy_callback, entry)
|
2016-03-03 09:10:21 +01:00
|
|
|
{
|
|
|
|
if (callback->cb == cb && callback->ctx == ctx)
|
|
|
|
{
|
|
|
|
list_remove(&callback->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, callback);
|
2016-03-04 05:20:18 +01:00
|
|
|
break;
|
2016-03-03 09:10:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3DRM_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-06 13:10:34 +02:00
|
|
|
HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name)
|
|
|
|
{
|
|
|
|
DWORD req_size;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
req_size = strlen(object->classname) + 1;
|
|
|
|
if (name && *size < req_size)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*size = req_size;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
memcpy(name, object->classname, req_size);
|
|
|
|
|
|
|
|
return D3DRM_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-21 14:39:30 +02:00
|
|
|
HRESULT d3drm_object_get_name(struct d3drm_object *object, DWORD *size, char *name)
|
|
|
|
{
|
|
|
|
DWORD req_size;
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
req_size = object->name ? strlen(object->name) + 1 : 0;
|
|
|
|
if (name && *size < req_size)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (object->name)
|
|
|
|
memcpy(name, object->name, req_size);
|
|
|
|
else if (*size)
|
|
|
|
*name = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*size = req_size;
|
|
|
|
|
|
|
|
return D3DRM_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT d3drm_object_set_name(struct d3drm_object *object, const char *name)
|
|
|
|
{
|
|
|
|
DWORD req_size;
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->name);
|
|
|
|
object->name = NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
req_size = strlen(name) + 1;
|
|
|
|
if (!(object->name = HeapAlloc(GetProcessHeap(), 0, req_size)))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memcpy(object->name, name, req_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3DRM_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-03 09:10:21 +01:00
|
|
|
void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
|
|
|
|
{
|
|
|
|
struct destroy_callback *callback, *callback2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE(callback, callback2, &object->destroy_callbacks, struct destroy_callback, entry)
|
|
|
|
{
|
|
|
|
callback->cb(iface, callback->ctx);
|
|
|
|
list_remove(&callback->entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, callback);
|
|
|
|
}
|
2017-06-21 14:39:30 +02:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, object->name);
|
|
|
|
object->name = NULL;
|
2016-03-03 09:10:21 +01:00
|
|
|
}
|