wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / d3drm / d3drm_main.c
blobbe7b8101fe8f26e6135ac0700d51fc824a707d41
1 /*
2 * Copyright 2004 Ivan Leo Puoti
3 * Copyright 2010 Christian Costa
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "initguid.h"
21 #include "d3drm_private.h"
23 void d3drm_object_init(struct d3drm_object *object, const char *classname)
25 object->ref = 1;
26 object->appdata = 0;
27 list_init(&object->destroy_callbacks);
28 object->classname = classname;
29 object->name = NULL;
32 struct destroy_callback
34 struct list entry;
35 D3DRMOBJECTCALLBACK cb;
36 void *ctx;
39 HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
41 struct destroy_callback *callback;
43 if (!cb)
44 return D3DRMERR_BADVALUE;
46 if (!(callback = heap_alloc(sizeof(*callback))))
47 return E_OUTOFMEMORY;
49 callback->cb = cb;
50 callback->ctx = ctx;
52 list_add_head(&object->destroy_callbacks, &callback->entry);
53 return D3DRM_OK;
56 HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
58 struct destroy_callback *callback;
60 if (!cb)
61 return D3DRMERR_BADVALUE;
63 LIST_FOR_EACH_ENTRY(callback, &object->destroy_callbacks, struct destroy_callback, entry)
65 if (callback->cb == cb && callback->ctx == ctx)
67 list_remove(&callback->entry);
68 heap_free(callback);
69 break;
73 return D3DRM_OK;
76 HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name)
78 DWORD req_size;
80 if (!size)
81 return E_INVALIDARG;
83 req_size = strlen(object->classname) + 1;
84 if (name && *size < req_size)
85 return E_INVALIDARG;
87 *size = req_size;
89 if (name)
90 memcpy(name, object->classname, req_size);
92 return D3DRM_OK;
95 HRESULT d3drm_object_get_name(struct d3drm_object *object, DWORD *size, char *name)
97 DWORD req_size;
99 if (!size)
100 return E_INVALIDARG;
102 req_size = object->name ? strlen(object->name) + 1 : 0;
103 if (name && *size < req_size)
104 return E_INVALIDARG;
106 if (name)
108 if (object->name)
109 memcpy(name, object->name, req_size);
110 else if (*size)
111 *name = 0;
114 *size = req_size;
116 return D3DRM_OK;
119 HRESULT d3drm_object_set_name(struct d3drm_object *object, const char *name)
121 DWORD req_size;
123 heap_free(object->name);
124 object->name = NULL;
126 if (name)
128 req_size = strlen(name) + 1;
129 if (!(object->name = heap_alloc(req_size)))
130 return E_OUTOFMEMORY;
131 memcpy(object->name, name, req_size);
134 return D3DRM_OK;
137 void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
139 struct destroy_callback *callback, *callback2;
141 LIST_FOR_EACH_ENTRY_SAFE(callback, callback2, &object->destroy_callbacks, struct destroy_callback, entry)
143 callback->cb(iface, callback->ctx);
144 list_remove(&callback->entry);
145 heap_free(callback);
148 heap_free(object->name);
149 object->name = NULL;