ntdll: Translate signal to trap when trap code is 0 on ARM.
[wine.git] / dlls / d3dx10_43 / async.c
blobc7d80c9db46e16f0cb91980b3fe46097920fcbbe
1 /*
2 * Copyright 2016 Andrey Gusev
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
21 #include "d3d10_1.h"
22 #include "d3dx10.h"
23 #include "d3dcompiler.h"
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
30 struct asyncdataloader
32 ID3DX10DataLoader ID3DX10DataLoader_iface;
34 union
36 struct
38 WCHAR *path;
39 } file;
40 struct
42 HMODULE module;
43 HRSRC rsrc;
44 } resource;
45 } u;
46 void *data;
47 SIZE_T size;
50 static inline struct asyncdataloader *impl_from_ID3DX10DataLoader(ID3DX10DataLoader *iface)
52 return CONTAINING_RECORD(iface, struct asyncdataloader, ID3DX10DataLoader_iface);
55 static HRESULT WINAPI memorydataloader_Load(ID3DX10DataLoader *iface)
57 TRACE("iface %p.\n", iface);
58 return S_OK;
61 static HRESULT WINAPI memorydataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
63 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
65 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
67 *data = loader->data;
68 *size = loader->size;
70 return S_OK;
73 static HRESULT WINAPI memorydataloader_Destroy(ID3DX10DataLoader *iface)
75 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
77 TRACE("iface %p.\n", iface);
79 HeapFree(GetProcessHeap(), 0, loader);
80 return S_OK;
83 static const ID3DX10DataLoaderVtbl memorydataloadervtbl =
85 memorydataloader_Load,
86 memorydataloader_Decompress,
87 memorydataloader_Destroy
90 static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface)
92 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
93 DWORD size, read_len;
94 HANDLE file;
95 void *data;
96 BOOL ret;
98 TRACE("iface %p.\n", iface);
100 /* Always buffer file contents, even if Load() was already called. */
101 file = CreateFileW(loader->u.file.path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
102 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
103 if (file == INVALID_HANDLE_VALUE)
104 return D3D10_ERROR_FILE_NOT_FOUND;
106 size = GetFileSize(file, NULL);
107 data = HeapAlloc(GetProcessHeap(), 0, size);
108 if (!data)
110 CloseHandle(file);
111 return E_OUTOFMEMORY;
114 ret = ReadFile(file, data, size, &read_len, NULL);
115 CloseHandle(file);
116 if (!ret)
118 WARN("Failed to read file contents.\n");
119 HeapFree(GetProcessHeap(), 0, data);
120 return E_FAIL;
123 HeapFree(GetProcessHeap(), 0, loader->data);
124 loader->data = data;
125 loader->size = size;
127 return S_OK;
130 static HRESULT WINAPI filedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
132 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
134 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
136 if (!loader->data)
137 return E_FAIL;
139 *data = loader->data;
140 *size = loader->size;
142 return S_OK;
145 static HRESULT WINAPI filedataloader_Destroy(ID3DX10DataLoader *iface)
147 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
149 TRACE("iface %p.\n", iface);
151 HeapFree(GetProcessHeap(), 0, loader->u.file.path);
152 HeapFree(GetProcessHeap(), 0, loader->data);
153 HeapFree(GetProcessHeap(), 0, loader);
155 return S_OK;
158 static const ID3DX10DataLoaderVtbl filedataloadervtbl =
160 filedataloader_Load,
161 filedataloader_Decompress,
162 filedataloader_Destroy
165 static HRESULT WINAPI resourcedataloader_Load(ID3DX10DataLoader *iface)
167 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
168 HGLOBAL hglobal;
170 TRACE("iface %p.\n", iface);
172 if (loader->data)
173 return S_OK;
175 hglobal = LoadResource(loader->u.resource.module, loader->u.resource.rsrc);
176 if (!hglobal)
178 WARN("Failed to load resource.\n");
179 return E_FAIL;
182 loader->data = LockResource(hglobal);
183 loader->size = SizeofResource(loader->u.resource.module, loader->u.resource.rsrc);
185 return S_OK;
188 static HRESULT WINAPI resourcedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
190 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
192 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
194 if (!loader->data)
195 return E_FAIL;
197 *data = loader->data;
198 *size = loader->size;
200 return S_OK;
203 static HRESULT WINAPI resourcedataloader_Destroy(ID3DX10DataLoader *iface)
205 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
207 TRACE("iface %p.\n", iface);
209 HeapFree(GetProcessHeap(), 0, loader);
211 return S_OK;
214 static const ID3DX10DataLoaderVtbl resourcedataloadervtbl =
216 resourcedataloader_Load,
217 resourcedataloader_Decompress,
218 resourcedataloader_Destroy
221 HRESULT WINAPI D3DX10CompileFromMemory(const char *data, SIZE_T data_size, const char *filename,
222 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point,
223 const char *target, UINT sflags, UINT eflags, ID3DX10ThreadPump *pump, ID3D10Blob **shader,
224 ID3D10Blob **error_messages, HRESULT *hresult)
226 TRACE("data %s, data_size %lu, filename %s, defines %p, include %p, entry_point %s, target %s, "
227 "sflags %#x, eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
228 debugstr_an(data, data_size), data_size, debugstr_a(filename), defines, include,
229 debugstr_a(entry_point), debugstr_a(target), sflags, eflags, pump, shader,
230 error_messages, hresult);
232 if (pump)
233 FIXME("Unimplemented ID3DX10ThreadPump handling.\n");
235 return D3DCompile(data, data_size, filename, defines, include, entry_point, target,
236 sflags, eflags, shader, error_messages);
239 HRESULT WINAPI D3DX10CreateEffectPoolFromFileA(const char *filename, const D3D10_SHADER_MACRO *defines,
240 ID3D10Include *include, const char *profile, UINT hlslflags, UINT fxflags, ID3D10Device *device,
241 ID3DX10ThreadPump *pump, ID3D10EffectPool **effectpool, ID3D10Blob **errors, HRESULT *hresult)
243 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
244 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
245 debugstr_a(filename), defines, include, debugstr_a(profile), hlslflags, fxflags, device,
246 pump, effectpool, errors, hresult);
248 return E_NOTIMPL;
251 HRESULT WINAPI D3DX10CreateEffectPoolFromFileW(const WCHAR *filename, const D3D10_SHADER_MACRO *defines,
252 ID3D10Include *include, const char *profile, UINT hlslflags, UINT fxflags, ID3D10Device *device,
253 ID3DX10ThreadPump *pump, ID3D10EffectPool **effectpool, ID3D10Blob **errors, HRESULT *hresult)
255 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
256 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
257 debugstr_w(filename), defines, include, debugstr_a(profile), hlslflags, fxflags, device,
258 pump, effectpool, errors, hresult);
260 return E_NOTIMPL;
263 HRESULT WINAPI D3DX10CreateAsyncMemoryLoader(const void *data, SIZE_T data_size, ID3DX10DataLoader **loader)
265 struct asyncdataloader *object;
267 TRACE("data %p, data_size %lu, loader %p.\n", data, data_size, loader);
269 if (!data || !loader)
270 return E_FAIL;
272 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
273 if (!object)
274 return E_OUTOFMEMORY;
276 object->ID3DX10DataLoader_iface.lpVtbl = &memorydataloadervtbl;
277 object->data = (void *)data;
278 object->size = data_size;
280 *loader = &object->ID3DX10DataLoader_iface;
282 return S_OK;
285 HRESULT WINAPI D3DX10CreateAsyncFileLoaderA(const char *filename, ID3DX10DataLoader **loader)
287 WCHAR *filename_w;
288 HRESULT hr;
289 int len;
291 TRACE("filename %s, loader %p.\n", debugstr_a(filename), loader);
293 if (!filename || !loader)
294 return E_FAIL;
296 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
297 filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*filename_w));
298 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
300 hr = D3DX10CreateAsyncFileLoaderW(filename_w, loader);
302 HeapFree(GetProcessHeap(), 0, filename_w);
304 return hr;
307 HRESULT WINAPI D3DX10CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX10DataLoader **loader)
309 struct asyncdataloader *object;
311 TRACE("filename %s, loader %p.\n", debugstr_w(filename), loader);
313 if (!filename || !loader)
314 return E_FAIL;
316 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
317 if (!object)
318 return E_OUTOFMEMORY;
320 object->ID3DX10DataLoader_iface.lpVtbl = &filedataloadervtbl;
321 object->u.file.path = HeapAlloc(GetProcessHeap(), 0, (strlenW(filename) + 1) * sizeof(WCHAR));
322 if (!object->u.file.path)
324 HeapFree(GetProcessHeap(), 0, object);
325 return E_OUTOFMEMORY;
327 strcpyW(object->u.file.path, filename);
328 object->data = NULL;
329 object->size = 0;
331 *loader = &object->ID3DX10DataLoader_iface;
333 return S_OK;
336 HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *resource, ID3DX10DataLoader **loader)
338 struct asyncdataloader *object;
339 HRSRC rsrc;
341 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_a(resource), loader);
343 if (!loader)
344 return E_FAIL;
346 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
347 if (!object)
348 return E_OUTOFMEMORY;
350 if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA)))
352 WARN("Failed to find resource.\n");
353 HeapFree(GetProcessHeap(), 0, object);
354 return D3DX10_ERR_INVALID_DATA;
357 object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
358 object->u.resource.module = module;
359 object->u.resource.rsrc = rsrc;
360 object->data = NULL;
361 object->size = 0;
363 *loader = &object->ID3DX10DataLoader_iface;
365 return S_OK;
368 HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *resource, ID3DX10DataLoader **loader)
370 struct asyncdataloader *object;
371 HRSRC rsrc;
373 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_w(resource), loader);
375 if (!loader)
376 return E_FAIL;
378 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
379 if (!object)
380 return E_OUTOFMEMORY;
382 if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
384 WARN("Failed to find resource.\n");
385 HeapFree(GetProcessHeap(), 0, object);
386 return D3DX10_ERR_INVALID_DATA;
389 object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
390 object->u.resource.module = module;
391 object->u.resource.rsrc = rsrc;
392 object->data = NULL;
393 object->size = 0;
395 *loader = &object->ID3DX10DataLoader_iface;
397 return S_OK;
400 HRESULT WINAPI D3DX10PreprocessShaderFromMemory(const char *data, SIZE_T data_size, const char *filename,
401 const D3D10_SHADER_MACRO *defines, ID3DInclude *include, ID3DX10ThreadPump *pump, ID3D10Blob **shader_text,
402 ID3D10Blob **errors, HRESULT *hresult)
404 FIXME("data %s, data_size %lu, filename %s, defines %p, include %p, pump %p, shader_text %p, "
405 "errors %p, hresult %p stub!\n",
406 debugstr_an(data, data_size), data_size, debugstr_a(filename), defines, include, pump,
407 shader_text, errors, hresult);
409 return E_NOTIMPL;