msacm32: Don't add a format entry if it is decode-only.
[wine.git] / dlls / d3dx10_43 / async.c
blobc6389042e14f9fd9f3d1e1907acd8ed8ab56aa0a
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 "d3dx10core.h"
24 #include "d3dcompiler.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
31 struct asyncdataloader
33 ID3DX10DataLoader ID3DX10DataLoader_iface;
35 union
37 struct
39 WCHAR *path;
40 } file;
41 struct
43 HMODULE module;
44 HRSRC rsrc;
45 } resource;
46 } u;
47 void *data;
48 SIZE_T size;
51 static inline struct asyncdataloader *impl_from_ID3DX10DataLoader(ID3DX10DataLoader *iface)
53 return CONTAINING_RECORD(iface, struct asyncdataloader, ID3DX10DataLoader_iface);
56 static HRESULT WINAPI memorydataloader_Load(ID3DX10DataLoader *iface)
58 TRACE("iface %p.\n", iface);
59 return S_OK;
62 static HRESULT WINAPI memorydataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
64 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
66 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
68 *data = loader->data;
69 *size = loader->size;
71 return S_OK;
74 static HRESULT WINAPI memorydataloader_Destroy(ID3DX10DataLoader *iface)
76 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
78 TRACE("iface %p.\n", iface);
80 HeapFree(GetProcessHeap(), 0, loader);
81 return S_OK;
84 static const ID3DX10DataLoaderVtbl memorydataloadervtbl =
86 memorydataloader_Load,
87 memorydataloader_Decompress,
88 memorydataloader_Destroy
91 static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface)
93 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
94 DWORD size, read_len;
95 HANDLE file;
96 void *data;
97 BOOL ret;
99 TRACE("iface %p.\n", iface);
101 /* Always buffer file contents, even if Load() was already called. */
102 file = CreateFileW(loader->u.file.path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
103 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
104 if (file == INVALID_HANDLE_VALUE)
105 return D3D10_ERROR_FILE_NOT_FOUND;
107 size = GetFileSize(file, NULL);
108 data = HeapAlloc(GetProcessHeap(), 0, size);
109 if (!data)
111 CloseHandle(file);
112 return E_OUTOFMEMORY;
115 ret = ReadFile(file, data, size, &read_len, NULL);
116 CloseHandle(file);
117 if (!ret)
119 ERR("Failed to read file contents.\n");
120 HeapFree(GetProcessHeap(), 0, data);
121 return E_FAIL;
124 HeapFree(GetProcessHeap(), 0, loader->data);
125 loader->data = data;
126 loader->size = size;
128 return S_OK;
131 static HRESULT WINAPI filedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
133 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
135 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
137 if (!loader->data)
138 return E_FAIL;
140 *data = loader->data;
141 *size = loader->size;
143 return S_OK;
146 static HRESULT WINAPI filedataloader_Destroy(ID3DX10DataLoader *iface)
148 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
150 TRACE("iface %p.\n", iface);
152 HeapFree(GetProcessHeap(), 0, loader->u.file.path);
153 HeapFree(GetProcessHeap(), 0, loader->data);
154 HeapFree(GetProcessHeap(), 0, loader);
156 return S_OK;
159 static const ID3DX10DataLoaderVtbl filedataloadervtbl =
161 filedataloader_Load,
162 filedataloader_Decompress,
163 filedataloader_Destroy
166 static HRESULT WINAPI resourcedataloader_Load(ID3DX10DataLoader *iface)
168 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
169 HGLOBAL hglobal;
171 TRACE("iface %p.\n", iface);
173 if (loader->data)
174 return S_OK;
176 hglobal = LoadResource(loader->u.resource.module, loader->u.resource.rsrc);
177 if (!hglobal)
179 ERR("Failed to load resource.\n");
180 return E_FAIL;
183 loader->data = LockResource(hglobal);
184 loader->size = SizeofResource(loader->u.resource.module, loader->u.resource.rsrc);
186 return S_OK;
189 static HRESULT WINAPI resourcedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
191 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
193 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
195 if (!loader->data)
196 return E_FAIL;
198 *data = loader->data;
199 *size = loader->size;
201 return S_OK;
204 static HRESULT WINAPI resourcedataloader_Destroy(ID3DX10DataLoader *iface)
206 struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
208 TRACE("iface %p.\n", iface);
210 HeapFree(GetProcessHeap(), 0, loader);
212 return S_OK;
215 static const ID3DX10DataLoaderVtbl resourcedataloadervtbl =
217 resourcedataloader_Load,
218 resourcedataloader_Decompress,
219 resourcedataloader_Destroy
222 HRESULT WINAPI D3DX10CompileFromMemory(const char *data, SIZE_T data_size, const char *filename,
223 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point,
224 const char *target, UINT sflags, UINT eflags, ID3DX10ThreadPump *pump, ID3D10Blob **shader,
225 ID3D10Blob **error_messages, HRESULT *hresult)
227 TRACE("data %s, data_size %lu, filename %s, defines %p, include %p, entry_point %s, target %s, "
228 "sflags %#x, eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
229 debugstr_an(data, data_size), data_size, debugstr_a(filename), defines, include,
230 debugstr_a(entry_point), debugstr_a(target), sflags, eflags, pump, shader,
231 error_messages, hresult);
233 if (pump)
234 FIXME("Unimplemented ID3DX10ThreadPump handling.\n");
236 return D3DCompile(data, data_size, filename, defines, include, entry_point, target,
237 sflags, eflags, shader, error_messages);
240 HRESULT WINAPI D3DX10CreateEffectPoolFromFileA(const char *filename, const D3D10_SHADER_MACRO *defines,
241 ID3D10Include *include, const char *profile, UINT hlslflags, UINT fxflags, ID3D10Device *device,
242 ID3DX10ThreadPump *pump, ID3D10EffectPool **effectpool, ID3D10Blob **errors, HRESULT *hresult)
244 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
245 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
246 debugstr_a(filename), defines, include, debugstr_a(profile), hlslflags, fxflags, device,
247 pump, effectpool, errors, hresult);
249 return E_NOTIMPL;
252 HRESULT WINAPI D3DX10CreateEffectPoolFromFileW(const WCHAR *filename, const D3D10_SHADER_MACRO *defines,
253 ID3D10Include *include, const char *profile, UINT hlslflags, UINT fxflags, ID3D10Device *device,
254 ID3DX10ThreadPump *pump, ID3D10EffectPool **effectpool, ID3D10Blob **errors, HRESULT *hresult)
256 FIXME("filename %s, defines %p, include %p, profile %s, hlslflags %#x, fxflags %#x, device %p, "
257 "pump %p, effectpool %p, errors %p, hresult %p, stub!\n",
258 debugstr_w(filename), defines, include, debugstr_a(profile), hlslflags, fxflags, device,
259 pump, effectpool, errors, hresult);
261 return E_NOTIMPL;
264 HRESULT WINAPI D3DX10CreateAsyncMemoryLoader(const void *data, SIZE_T data_size, ID3DX10DataLoader **loader)
266 struct asyncdataloader *object;
268 TRACE("data %p, data_size %lu, loader %p.\n", data, data_size, loader);
270 if (!data || !loader)
271 return E_FAIL;
273 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
274 if (!object)
275 return E_OUTOFMEMORY;
277 object->ID3DX10DataLoader_iface.lpVtbl = &memorydataloadervtbl;
278 object->data = (void *)data;
279 object->size = data_size;
281 *loader = &object->ID3DX10DataLoader_iface;
283 return S_OK;
286 HRESULT WINAPI D3DX10CreateAsyncFileLoaderA(const char *filename, ID3DX10DataLoader **loader)
288 WCHAR *filename_w;
289 HRESULT hr;
290 int len;
292 TRACE("filename %s, loader %p.\n", debugstr_a(filename), loader);
294 if (!filename || !loader)
295 return E_FAIL;
297 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
298 filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*filename_w));
299 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
301 hr = D3DX10CreateAsyncFileLoaderW(filename_w, loader);
303 HeapFree(GetProcessHeap(), 0, filename_w);
305 return hr;
308 HRESULT WINAPI D3DX10CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX10DataLoader **loader)
310 struct asyncdataloader *object;
312 TRACE("filename %s, loader %p.\n", debugstr_w(filename), loader);
314 if (!filename || !loader)
315 return E_FAIL;
317 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
318 if (!object)
319 return E_OUTOFMEMORY;
321 object->ID3DX10DataLoader_iface.lpVtbl = &filedataloadervtbl;
322 object->u.file.path = HeapAlloc(GetProcessHeap(), 0, (strlenW(filename) + 1) * sizeof(WCHAR));
323 if (!object->u.file.path)
325 HeapFree(GetProcessHeap(), 0, object);
326 return E_OUTOFMEMORY;
328 strcpyW(object->u.file.path, filename);
329 object->data = NULL;
330 object->size = 0;
332 *loader = &object->ID3DX10DataLoader_iface;
334 return S_OK;
337 HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *resource, ID3DX10DataLoader **loader)
339 struct asyncdataloader *object;
340 HRSRC rsrc;
342 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_a(resource), loader);
344 if (!loader)
345 return E_FAIL;
347 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
348 if (!object)
349 return E_OUTOFMEMORY;
351 if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA)))
353 ERR("Failed to find resource.\n");
354 HeapFree(GetProcessHeap(), 0, object);
355 return D3DX10_ERR_INVALID_DATA;
358 object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
359 object->u.resource.module = module;
360 object->u.resource.rsrc = rsrc;
361 object->data = NULL;
362 object->size = 0;
364 *loader = &object->ID3DX10DataLoader_iface;
366 return S_OK;
369 HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *resource, ID3DX10DataLoader **loader)
371 struct asyncdataloader *object;
372 HRSRC rsrc;
374 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_w(resource), loader);
376 if (!loader)
377 return E_FAIL;
379 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
380 if (!object)
381 return E_OUTOFMEMORY;
383 if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
385 ERR("Failed to find resource.\n");
386 HeapFree(GetProcessHeap(), 0, object);
387 return D3DX10_ERR_INVALID_DATA;
390 object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
391 object->u.resource.module = module;
392 object->u.resource.rsrc = rsrc;
393 object->data = NULL;
394 object->size = 0;
396 *loader = &object->ID3DX10DataLoader_iface;
398 return S_OK;