ReactOS  0.4.15-dev-494-g1d8c567
d3drm_main.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004 Ivan Leo Puoti
3  * Copyright 2010 Christian Costa
4  *
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.
9  *
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.
14  *
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
18  */
19 
20 #include "initguid.h"
21 #include "d3drm_private.h"
22 
23 /***********************************************************************
24  * DllMain (D3DRM.@)
25  */
27 {
28  switch(reason)
29  {
30  case DLL_WINE_PREATTACH:
31  return FALSE; /* prefer native version */
32  case DLL_PROCESS_ATTACH:
34  break;
35  }
36  return TRUE;
37 }
38 
39 void d3drm_object_init(struct d3drm_object *object, const char *classname)
40 {
41  object->ref = 1;
42  object->appdata = 0;
43  list_init(&object->destroy_callbacks);
44  object->classname = classname;
45  object->name = NULL;
46 }
47 
49 {
50  struct list entry;
52  void *ctx;
53 };
54 
56 {
57  struct destroy_callback *callback;
58 
59  if (!cb)
60  return D3DRMERR_BADVALUE;
61 
62  if (!(callback = heap_alloc(sizeof(*callback))))
63  return E_OUTOFMEMORY;
64 
65  callback->cb = cb;
66  callback->ctx = ctx;
67 
68  list_add_head(&object->destroy_callbacks, &callback->entry);
69  return D3DRM_OK;
70 }
71 
73 {
74  struct destroy_callback *callback;
75 
76  if (!cb)
77  return D3DRMERR_BADVALUE;
78 
79  LIST_FOR_EACH_ENTRY(callback, &object->destroy_callbacks, struct destroy_callback, entry)
80  {
81  if (callback->cb == cb && callback->ctx == ctx)
82  {
83  list_remove(&callback->entry);
85  break;
86  }
87  }
88 
89  return D3DRM_OK;
90 }
91 
93 {
94  DWORD req_size;
95 
96  if (!size)
97  return E_INVALIDARG;
98 
99  req_size = strlen(object->classname) + 1;
100  if (name && *size < req_size)
101  return E_INVALIDARG;
102 
103  *size = req_size;
104 
105  if (name)
106  memcpy(name, object->classname, req_size);
107 
108  return D3DRM_OK;
109 }
110 
112 {
113  DWORD req_size;
114 
115  if (!size)
116  return E_INVALIDARG;
117 
118  req_size = object->name ? strlen(object->name) + 1 : 0;
119  if (name && *size < req_size)
120  return E_INVALIDARG;
121 
122  if (name)
123  {
124  if (object->name)
125  memcpy(name, object->name, req_size);
126  else if (*size)
127  *name = 0;
128  }
129 
130  *size = req_size;
131 
132  return D3DRM_OK;
133 }
134 
135 HRESULT d3drm_object_set_name(struct d3drm_object *object, const char *name)
136 {
137  DWORD req_size;
138 
139  heap_free(object->name);
140  object->name = NULL;
141 
142  if (name)
143  {
144  req_size = strlen(name) + 1;
145  if (!(object->name = heap_alloc(req_size)))
146  return E_OUTOFMEMORY;
147  memcpy(object->name, name, req_size);
148  }
149 
150  return D3DRM_OK;
151 }
152 
153 void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
154 {
155  struct destroy_callback *callback, *callback2;
156 
157  LIST_FOR_EACH_ENTRY_SAFE(callback, callback2, &object->destroy_callbacks, struct destroy_callback, entry)
158  {
159  callback->cb(iface, callback->ctx);
160  list_remove(&callback->entry);
162  }
163 
164  heap_free(object->name);
165  object->name = NULL;
166 }
void d3drm_object_cleanup(IDirect3DRMObject *iface, struct d3drm_object *object)
Definition: d3drm_main.c:153
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
__WINE_SERVER_LIST_INLINE void list_add_head(struct list *list, struct list *elem)
Definition: list.h:96
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
Definition: d3drm_main.c:55
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
struct list entry
Definition: d3drm_main.c:50
WCHAR classname[128]
Definition: startup.c:15
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned int BOOL
Definition: ntddk_ex.h:94
r reserved
Definition: btrfs.c:2940
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
HRESULT d3drm_object_get_name(struct d3drm_object *object, DWORD *size, char *name)
Definition: d3drm_main.c:111
BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
Definition: d3drm_main.c:26
HRESULT d3drm_object_get_class_name(struct d3drm_object *object, DWORD *size, char *name)
Definition: d3drm_main.c:92
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
MmuTrapHandler callback[0x30]
Definition: mmuobject.c:44
GLsizeiptr size
Definition: glext.h:5919
LONG HRESULT
Definition: typedefs.h:78
#define D3DRM_OK
Definition: d3drm.h:486
#define WINAPI
Definition: msvc.h:6
char * name
Definition: compiler.c:66
unsigned long DWORD
Definition: ntddk_ex.h:95
D3DRMOBJECTCALLBACK cb
Definition: d3drm_main.c:51
void(__cdecl * D3DRMOBJECTCALLBACK)(struct IDirect3DRMObject *obj, void *arg)
Definition: d3drmobj.h:157
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
HRESULT d3drm_object_delete_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx)
Definition: d3drm_main.c:72
#define D3DRMERR_BADVALUE
Definition: d3drm.h:496
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: _list.h:228
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
void d3drm_object_init(struct d3drm_object *object, const char *classname)
Definition: d3drm_main.c:39
static HMODULE MODULEINFO DWORD cb
Definition: module.c:32
Definition: name.c:38
__WINE_SERVER_LIST_INLINE void list_init(struct list *list)
Definition: list.h:149
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
HRESULT d3drm_object_set_name(struct d3drm_object *object, const char *name)
Definition: d3drm_main.c:135