winmm: Avoid explicitly casting the pointer returned from Heap(Re)Alloc.
[wine.git] / dlls / d3d9 / d3d9_main.c
blob5b525c97ff3055476f55ff19d97ca85c2d19ec62
1 /*
2 * Direct3D 9
4 * Copyright 2002-2003 Jason Edmeades
5 * Copyright 2002-2003 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "initguid.h"
25 #include "d3d9_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
29 static int D3DPERF_event_level = 0;
31 void WINAPI DebugSetMute(void) {
32 /* nothing to do */
35 IDirect3D9 * WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT sdk_version)
37 struct d3d9 *object;
39 TRACE("sdk_version %#x.\n", sdk_version);
41 if (!(object = heap_alloc_zero(sizeof(*object))))
42 return NULL;
44 if (!d3d9_init(object, FALSE))
46 WARN("Failed to initialize d3d9.\n");
47 heap_free(object);
48 return NULL;
51 TRACE("Created d3d9 object %p.\n", object);
53 return (IDirect3D9 *)&object->IDirect3D9Ex_iface;
56 HRESULT WINAPI DECLSPEC_HOTPATCH Direct3DCreate9Ex(UINT sdk_version, IDirect3D9Ex **d3d9ex)
58 struct d3d9 *object;
60 TRACE("sdk_version %#x, d3d9ex %p.\n", sdk_version, d3d9ex);
62 if (!(object = heap_alloc_zero(sizeof(*object))))
63 return E_OUTOFMEMORY;
65 if (!d3d9_init(object, TRUE))
67 WARN("Failed to initialize d3d9.\n");
68 heap_free(object);
69 return D3DERR_NOTAVAILABLE;
72 TRACE("Created d3d9 object %p.\n", object);
73 *d3d9ex = &object->IDirect3D9Ex_iface;
75 return D3D_OK;
78 /* The callback is called on any error encountered during validation, including
79 * improper IDirect3DShaderValidator9 method calls.
80 * - "file" and "line" are passed through directly from Instruction(). "line"
81 * is provably 32-bit, as 64-bit values passed to Instruction() will be
82 * truncated.
83 * - "arg3" has been observed to be at least 0, 2, and 6. The integer size is
84 * not known.
85 * - "message_id" is a numeric error code. fxc.exe adds 5000 before printing
86 * it. The integer size is not known.
87 * - "context" is passed through directly from Begin().
89 * Improper calls to IDirect3DShaderValidator9 methods, or other errors not
90 * generated by specific Instruction() calls, yield NULL as the file, and
91 * either 0 or -1 as the line.
93 * The callback return type is not known, but programs (fxc.exe, The Sims 2)
94 * seem to consistently return 0.
96 * The interface and method names below are derived from the messages that
97 * native d3d9 prints on said improper method calls.
99 * Calls to Begin(), Instruction(), End() have been observed to return S_OK and
100 * E_FAIL. E_FAIL is not always returned if an error message is handed to the
101 * callback. */
103 typedef HRESULT (WINAPI *shader_validator_cb)(const char *file, int line,
104 DWORD_PTR arg3, DWORD_PTR message_id, const char *message, void *context);
106 typedef struct IDirect3DShaderValidator9 IDirect3DShaderValidator9;
108 struct IDirect3DShaderValidator9Vtbl
110 HRESULT (WINAPI *QueryInterface)(IDirect3DShaderValidator9 *iface, REFIID iid, void **out);
111 ULONG (WINAPI *AddRef)(IDirect3DShaderValidator9 *iface);
112 ULONG (WINAPI *Release)(IDirect3DShaderValidator9 *iface);
113 HRESULT (WINAPI *Begin)(IDirect3DShaderValidator9 *iface,
114 shader_validator_cb callback, void *context, DWORD_PTR arg3);
115 HRESULT (WINAPI *Instruction)(IDirect3DShaderValidator9 *iface,
116 const char *file, int line, const DWORD *tokens, unsigned int token_count);
117 HRESULT (WINAPI *End)(IDirect3DShaderValidator9 *iface);
120 struct IDirect3DShaderValidator9
122 const struct IDirect3DShaderValidator9Vtbl *vtbl;
125 static HRESULT WINAPI shader_validator_QueryInterface(IDirect3DShaderValidator9 *iface, REFIID iid, void **out)
127 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
129 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
130 *out = NULL;
132 return E_NOINTERFACE;
135 static ULONG WINAPI shader_validator_AddRef(IDirect3DShaderValidator9 *iface)
137 TRACE("iface %p.\n", iface);
139 return 2;
142 static ULONG WINAPI shader_validator_Release(IDirect3DShaderValidator9 *iface)
144 TRACE("iface %p.\n", iface);
146 return 1;
149 /* The size and type of the third argument is not known. The Sims 2 passes 0;
150 * fxc.exe passes 1. */
151 static HRESULT WINAPI shader_validator_Begin(IDirect3DShaderValidator9 *iface,
152 shader_validator_cb callback, void *context, DWORD_PTR arg3)
154 WARN("iface %p, callback %p, context %p, arg3 %#Ix, stub!\n", iface, callback, context, arg3);
156 return S_OK;
159 /* - "file" and "line" are passed directly through to the callback.
160 * - "tokens" comprises a single instruction; the caller must determine its
161 * length.
162 * - "token_count" is in DWORDs. */
163 static HRESULT WINAPI shader_validator_Instruction(IDirect3DShaderValidator9 *iface,
164 const char *file, int line, const DWORD *tokens, unsigned int token_count)
166 WARN("iface %p, file %s, line %u, tokens %p, token_count %u, stub!\n",
167 iface, debugstr_a(file), line, tokens, token_count);
169 return S_OK;
172 static HRESULT WINAPI shader_validator_End(IDirect3DShaderValidator9 *iface)
174 WARN("iface %p, stub!\n", iface);
176 return S_OK;
179 static const struct IDirect3DShaderValidator9Vtbl shader_validator_vtbl =
181 shader_validator_QueryInterface,
182 shader_validator_AddRef,
183 shader_validator_Release,
184 shader_validator_Begin,
185 shader_validator_Instruction,
186 shader_validator_End,
189 static IDirect3DShaderValidator9 shader_validator = {&shader_validator_vtbl};
191 IDirect3DShaderValidator9 * WINAPI Direct3DShaderValidatorCreate9(void)
193 FIXME("Returning stub validator %p.\n", &shader_validator);
195 return &shader_validator;
198 /***********************************************************************
199 * D3DPERF_BeginEvent (D3D9.@)
201 int WINAPI D3DPERF_BeginEvent(D3DCOLOR color, const WCHAR *name)
203 TRACE("color 0x%08lx, name %s.\n", color, debugstr_w(name));
205 return D3DPERF_event_level++;
208 /***********************************************************************
209 * D3DPERF_EndEvent (D3D9.@)
211 int WINAPI D3DPERF_EndEvent(void) {
212 TRACE("(void) : stub\n");
214 return --D3DPERF_event_level;
217 /***********************************************************************
218 * D3DPERF_GetStatus (D3D9.@)
220 DWORD WINAPI D3DPERF_GetStatus(void) {
221 FIXME("(void) : stub\n");
223 return 0;
226 /***********************************************************************
227 * D3DPERF_SetOptions (D3D9.@)
230 void WINAPI D3DPERF_SetOptions(DWORD options)
232 FIXME("options %#lx, stub!\n", options);
235 /***********************************************************************
236 * D3DPERF_QueryRepeatFrame (D3D9.@)
238 BOOL WINAPI D3DPERF_QueryRepeatFrame(void) {
239 FIXME("(void) : stub\n");
241 return FALSE;
244 /***********************************************************************
245 * D3DPERF_SetMarker (D3D9.@)
247 void WINAPI D3DPERF_SetMarker(D3DCOLOR color, const WCHAR *name)
249 FIXME("color 0x%08lx, name %s stub!\n", color, debugstr_w(name));
252 /***********************************************************************
253 * D3DPERF_SetRegion (D3D9.@)
255 void WINAPI D3DPERF_SetRegion(D3DCOLOR color, const WCHAR *name)
257 FIXME("color 0x%08lx, name %s stub!\n", color, debugstr_w(name));
260 void d3d9_resource_cleanup(struct d3d9_resource *resource)
262 wined3d_private_store_cleanup(&resource->private_store);
265 HRESULT d3d9_resource_free_private_data(struct d3d9_resource *resource, const GUID *guid)
267 struct wined3d_private_data *entry;
269 wined3d_mutex_lock();
270 entry = wined3d_private_store_get_private_data(&resource->private_store, guid);
271 if (!entry)
273 wined3d_mutex_unlock();
274 return D3DERR_NOTFOUND;
277 wined3d_private_store_free_private_data(&resource->private_store, entry);
278 wined3d_mutex_unlock();
280 return D3D_OK;
283 HRESULT d3d9_resource_get_private_data(struct d3d9_resource *resource, const GUID *guid,
284 void *data, DWORD *data_size)
286 const struct wined3d_private_data *stored_data;
287 DWORD size_in;
288 HRESULT hr;
290 wined3d_mutex_lock();
291 stored_data = wined3d_private_store_get_private_data(&resource->private_store, guid);
292 if (!stored_data)
294 hr = D3DERR_NOTFOUND;
295 goto done;
298 size_in = *data_size;
299 *data_size = stored_data->size;
300 if (!data)
302 hr = D3D_OK;
303 goto done;
305 if (size_in < stored_data->size)
307 hr = D3DERR_MOREDATA;
308 goto done;
311 if (stored_data->flags & WINED3DSPD_IUNKNOWN)
312 IUnknown_AddRef(stored_data->content.object);
313 memcpy(data, stored_data->content.data, stored_data->size);
314 hr = D3D_OK;
316 done:
317 wined3d_mutex_unlock();
318 return hr;
321 void d3d9_resource_init(struct d3d9_resource *resource)
323 resource->refcount = 1;
324 wined3d_private_store_init(&resource->private_store);
327 HRESULT d3d9_resource_set_private_data(struct d3d9_resource *resource, const GUID *guid,
328 const void *data, DWORD data_size, DWORD flags)
330 HRESULT hr;
332 wined3d_mutex_lock();
333 hr = wined3d_private_store_set_private_data(&resource->private_store, guid, data, data_size, flags);
334 wined3d_mutex_unlock();
335 return hr;