ntdll: Load .so builtin modules without using libwine.
[wine/zf.git] / dlls / d3dx10_43 / async.c
blob062a04d739cb0220a18a148e4e8c00b0749d8f96
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 "d3d10_1.h"
20 #include "d3dx10.h"
21 #include "d3dcompiler.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
27 struct asyncdataloader
29 ID3DX10DataLoader ID3DX10DataLoader_iface;
31 union
33 struct
35 WCHAR *path;
36 } file;
37 struct
39 HMODULE module;
40 HRSRC rsrc;
41 } resource;
42 } u;
43 void *data;
44 SIZE_T size;
47 static inline struct asyncdataloader *impl_from_ID3DX10DataLoader(ID3DX10DataLoader *iface)
49 return CONTAINING_RECORD(iface, struct asyncdataloader, ID3DX10DataLoader_iface);
52 static HRESULT WINAPI memorydataloader_Load(ID3DX10DataLoader *iface)
54 TRACE("iface %p.\n", iface);
55 return S_OK;
58 static HRESULT WINAPI memorydataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
60 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
62 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
64 *data = loader->data;
65 *size = loader->size;
67 return S_OK;
70 static HRESULT WINAPI memorydataloader_Destroy(ID3DX10DataLoader *iface)
72 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
74 TRACE("iface %p.\n", iface);
76 HeapFree(GetProcessHeap(), 0, loader);
77 return S_OK;
80 static const ID3DX10DataLoaderVtbl memorydataloadervtbl =
82 memorydataloader_Load,
83 memorydataloader_Decompress,
84 memorydataloader_Destroy
87 static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface)
89 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
90 DWORD size, read_len;
91 HANDLE file;
92 void *data;
93 BOOL ret;
95 TRACE("iface %p.\n", iface);
97 /* Always buffer file contents, even if Load() was already called. */
98 file = CreateFileW(loader->u.file.path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
99 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
100 if (file == INVALID_HANDLE_VALUE)
101 return D3D10_ERROR_FILE_NOT_FOUND;
103 size = GetFileSize(file, NULL);
104 data = HeapAlloc(GetProcessHeap(), 0, size);
105 if (!data)
107 CloseHandle(file);
108 return E_OUTOFMEMORY;
111 ret = ReadFile(file, data, size, &read_len, NULL);
112 CloseHandle(file);
113 if (!ret)
115 WARN("Failed to read file contents.\n");
116 HeapFree(GetProcessHeap(), 0, data);
117 return E_FAIL;
120 HeapFree(GetProcessHeap(), 0, loader->data);
121 loader->data = data;
122 loader->size = size;
124 return S_OK;
127 static HRESULT WINAPI filedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
129 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
131 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
133 if (!loader->data)
134 return E_FAIL;
136 *data = loader->data;
137 *size = loader->size;
139 return S_OK;
142 static HRESULT WINAPI filedataloader_Destroy(ID3DX10DataLoader *iface)
144 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
146 TRACE("iface %p.\n", iface);
148 HeapFree(GetProcessHeap(), 0, loader->u.file.path);
149 HeapFree(GetProcessHeap(), 0, loader->data);
150 HeapFree(GetProcessHeap(), 0, loader);
152 return S_OK;
155 static const ID3DX10DataLoaderVtbl filedataloadervtbl =
157 filedataloader_Load,
158 filedataloader_Decompress,
159 filedataloader_Destroy
162 static HRESULT WINAPI resourcedataloader_Load(ID3DX10DataLoader *iface)
164 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
165 HGLOBAL hglobal;
167 TRACE("iface %p.\n", iface);
169 if (loader->data)
170 return S_OK;
172 hglobal = LoadResource(loader->u.resource.module, loader->u.resource.rsrc);
173 if (!hglobal)
175 WARN("Failed to load resource.\n");
176 return E_FAIL;
179 loader->data = LockResource(hglobal);
180 loader->size = SizeofResource(loader->u.resource.module, loader->u.resource.rsrc);
182 return S_OK;
185 static HRESULT WINAPI resourcedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
187 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
189 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
191 if (!loader->data)
192 return E_FAIL;
194 *data = loader->data;
195 *size = loader->size;
197 return S_OK;
200 static HRESULT WINAPI resourcedataloader_Destroy(ID3DX10DataLoader *iface)
202 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
204 TRACE("iface %p.\n", iface);
206 HeapFree(GetProcessHeap(), 0, loader);
208 return S_OK;
211 static const ID3DX10DataLoaderVtbl resourcedataloadervtbl =
213 resourcedataloader_Load,
214 resourcedataloader_Decompress,
215 resourcedataloader_Destroy
218 HRESULT WINAPI D3DX10CompileFromMemory(const char *data, SIZE_T data_size, const char *filename,
219 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point,
220 const char *target, UINT sflags, UINT eflags, ID3DX10ThreadPump *pump, ID3D10Blob **shader,
221 ID3D10Blob **error_messages, HRESULT *hresult)
223 TRACE("data %s, data_size %lu, filename %s, defines %p, include %p, entry_point %s, target %s, "
224 "sflags %#x, eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
225 debugstr_an(data, data_size), data_size, debugstr_a(filename), defines, include,
226 debugstr_a(entry_point), debugstr_a(target), sflags, eflags, pump, shader,
227 error_messages, hresult);
229 if (pump)
230 FIXME("Unimplemented ID3DX10ThreadPump handling.\n");
232 return D3DCompile(data, data_size, filename, defines, include, entry_point, target,
233 sflags, eflags, shader, error_messages);
236 HRESULT WINAPI D3DX10CreateEffectPoolFromFileA(const char *filename, const D3D10_SHADER_MACRO *defines,
237 ID3D10Include *include, const char *profile, UINT hlslflags, UINT fxflags, ID3D10Device *device,
238 ID3DX10ThreadPump *pump, ID3D10EffectPool **effectpool, ID3D10Blob **errors, HRESULT *hresult)
240 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
241 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
242 debugstr_a(filename), defines, include, debugstr_a(profile), hlslflags, fxflags, device,
243 pump, effectpool, errors, hresult);
245 return E_NOTIMPL;
248 HRESULT WINAPI D3DX10CreateEffectPoolFromFileW(const WCHAR *filename, const D3D10_SHADER_MACRO *defines,
249 ID3D10Include *include, const char *profile, UINT hlslflags, UINT fxflags, ID3D10Device *device,
250 ID3DX10ThreadPump *pump, ID3D10EffectPool **effectpool, ID3D10Blob **errors, HRESULT *hresult)
252 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
253 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
254 debugstr_w(filename), defines, include, debugstr_a(profile), hlslflags, fxflags, device,
255 pump, effectpool, errors, hresult);
257 return E_NOTIMPL;
260 HRESULT WINAPI D3DX10CreateAsyncMemoryLoader(const void *data, SIZE_T data_size, ID3DX10DataLoader **loader)
262 struct asyncdataloader *object;
264 TRACE("data %p, data_size %lu, loader %p.\n", data, data_size, loader);
266 if (!data || !loader)
267 return E_FAIL;
269 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
270 if (!object)
271 return E_OUTOFMEMORY;
273 object->ID3DX10DataLoader_iface.lpVtbl = &memorydataloadervtbl;
274 object->data = (void *)data;
275 object->size = data_size;
277 *loader = &object->ID3DX10DataLoader_iface;
279 return S_OK;
282 HRESULT WINAPI D3DX10CreateAsyncFileLoaderA(const char *filename, ID3DX10DataLoader **loader)
284 WCHAR *filename_w;
285 HRESULT hr;
286 int len;
288 TRACE("filename %s, loader %p.\n", debugstr_a(filename), loader);
290 if (!filename || !loader)
291 return E_FAIL;
293 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
294 filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*filename_w));
295 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
297 hr = D3DX10CreateAsyncFileLoaderW(filename_w, loader);
299 HeapFree(GetProcessHeap(), 0, filename_w);
301 return hr;
304 HRESULT WINAPI D3DX10CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX10DataLoader **loader)
306 struct asyncdataloader *object;
308 TRACE("filename %s, loader %p.\n", debugstr_w(filename), loader);
310 if (!filename || !loader)
311 return E_FAIL;
313 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
314 if (!object)
315 return E_OUTOFMEMORY;
317 object->ID3DX10DataLoader_iface.lpVtbl = &filedataloadervtbl;
318 object->u.file.path = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1) * sizeof(WCHAR));
319 if (!object->u.file.path)
321 HeapFree(GetProcessHeap(), 0, object);
322 return E_OUTOFMEMORY;
324 lstrcpyW(object->u.file.path, filename);
325 object->data = NULL;
326 object->size = 0;
328 *loader = &object->ID3DX10DataLoader_iface;
330 return S_OK;
333 HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *resource, ID3DX10DataLoader **loader)
335 struct asyncdataloader *object;
336 HRSRC rsrc;
338 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_a(resource), loader);
340 if (!loader)
341 return E_FAIL;
343 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
344 if (!object)
345 return E_OUTOFMEMORY;
347 if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA)))
349 WARN("Failed to find resource.\n");
350 HeapFree(GetProcessHeap(), 0, object);
351 return D3DX10_ERR_INVALID_DATA;
354 object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
355 object->u.resource.module = module;
356 object->u.resource.rsrc = rsrc;
357 object->data = NULL;
358 object->size = 0;
360 *loader = &object->ID3DX10DataLoader_iface;
362 return S_OK;
365 HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *resource, ID3DX10DataLoader **loader)
367 struct asyncdataloader *object;
368 HRSRC rsrc;
370 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_w(resource), loader);
372 if (!loader)
373 return E_FAIL;
375 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
376 if (!object)
377 return E_OUTOFMEMORY;
379 if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
381 WARN("Failed to find resource.\n");
382 HeapFree(GetProcessHeap(), 0, object);
383 return D3DX10_ERR_INVALID_DATA;
386 object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
387 object->u.resource.module = module;
388 object->u.resource.rsrc = rsrc;
389 object->data = NULL;
390 object->size = 0;
392 *loader = &object->ID3DX10DataLoader_iface;
394 return S_OK;
397 HRESULT WINAPI D3DX10PreprocessShaderFromMemory(const char *data, SIZE_T data_size, const char *filename,
398 const D3D10_SHADER_MACRO *defines, ID3DInclude *include, ID3DX10ThreadPump *pump, ID3D10Blob **shader_text,
399 ID3D10Blob **errors, HRESULT *hresult)
401 FIXME("data %s, data_size %lu, filename %s, defines %p, include %p, pump %p, shader_text %p, "
402 "errors %p, hresult %p stub!\n",
403 debugstr_an(data, data_size), data_size, debugstr_a(filename), defines, include, pump,
404 shader_text, errors, hresult);
406 return E_NOTIMPL;