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
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
2018-02-08 22:58:47 +01:00
|
|
|
if (!(callback = heap_alloc(sizeof(*callback))))
|
2016-03-03 09:10:21 +01:00
|
|
|
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);
|
2018-02-08 22:58:47 +01:00
|
|
|
heap_free(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;
|
|
|
|
|
2018-02-08 22:58:47 +01:00
|
|
|
heap_free(object->name);
|
2017-06-21 14:39:30 +02:00
|
|
|
object->name = NULL;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
req_size = strlen(name) + 1;
|
2018-02-08 22:58:47 +01:00
|
|
|
if (!(object->name = heap_alloc(req_size)))
|
2017-06-21 14:39:30 +02:00
|
|
|
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);
|
2018-02-08 22:58:47 +01:00
|
|
|
heap_free(callback);
|
2016-03-03 09:10:21 +01:00
|
|
|
}
|
2017-06-21 14:39:30 +02:00
|
|
|
|
2018-02-08 22:58:47 +01:00
|
|
|
heap_free(object->name);
|
2017-06-21 14:39:30 +02:00
|
|
|
object->name = NULL;
|
2016-03-03 09:10:21 +01:00
|
|
|
}
|