ReactOS 0.4.17-dev-923-g4c9a150
async.c
Go to the documentation of this file.
1/*
2 * Copyright 2016 Matteo Bruni for CodeWeavers
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "d3dx11.h"
20#include "d3dcompiler.h"
21
22#include "wine/debug.h"
23
25
26struct asyncdataloader
27{
29
30 union
31 {
32 struct
33 {
34 WCHAR *path;
36 struct
37 {
39 HRSRC rsrc;
41 } u;
42 void *data;
44};
45
47{
49}
50
52{
53 TRACE("iface %p.\n", iface);
54 return S_OK;
55}
56
58{
60
61 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
62
63 *data = loader->data;
64 *size = loader->size;
65
66 return S_OK;
67}
68
70{
72
73 TRACE("iface %p.\n", iface);
74
75 free(loader);
76 return S_OK;
77}
78
79static const ID3DX11DataLoaderVtbl memorydataloadervtbl =
80{
84};
85
87{
89 DWORD size, read_len;
91 void *data;
92 BOOL ret;
93
94 TRACE("iface %p.\n", iface);
95
96 /* Always buffer file contents, even if Load() was already called. */
101
103 data = malloc(size);
104 if (!data)
105 {
107 return E_OUTOFMEMORY;
108 }
109
110 ret = ReadFile(file, data, size, &read_len, NULL);
112 if (!ret)
113 {
114 ERR("Failed to read file contents.\n");
115 free(data);
116 return E_FAIL;
117 }
118
119 free(loader->data);
120 loader->data = data;
121 loader->size = size;
122
123 return S_OK;
124}
125
127{
129
130 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
131
132 if (!loader->data)
133 return E_FAIL;
134
135 *data = loader->data;
136 *size = loader->size;
137
138 return S_OK;
139}
140
142{
144
145 TRACE("iface %p.\n", iface);
146
147 free(loader->u.file.path);
148 free(loader->data);
149 free(loader);
150
151 return S_OK;
152}
153
154static const ID3DX11DataLoaderVtbl filedataloadervtbl =
155{
159};
160
162{
164 HGLOBAL hglobal;
165
166 TRACE("iface %p.\n", iface);
167
168 if (loader->data)
169 return S_OK;
170
171 hglobal = LoadResource(loader->u.resource.module, loader->u.resource.rsrc);
172 if (!hglobal)
173 {
174 ERR("Failed to load resource.\n");
175 return E_FAIL;
176 }
177
178 loader->data = LockResource(hglobal);
179 loader->size = SizeofResource(loader->u.resource.module, loader->u.resource.rsrc);
180
181 return S_OK;
182}
183
185{
187
188 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
189
190 if (!loader->data)
191 return E_FAIL;
192
193 *data = loader->data;
194 *size = loader->size;
195
196 return S_OK;
197}
198
200{
202
203 TRACE("iface %p.\n", iface);
204
205 free(loader);
206
207 return S_OK;
208}
209
210static const ID3DX11DataLoaderVtbl resourcedataloadervtbl =
211{
215};
216
217HRESULT WINAPI D3DX11CompileFromMemory(const char *data, SIZE_T data_size, const char *filename,
218 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point,
221{
222 TRACE("data %s, data_size %Iu, filename %s, defines %p, include %p, entry_point %s, target %s, "
223 "sflags %#x, eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
224 debugstr_an(data, data_size), data_size, debugstr_a(filename), defines, include,
225 debugstr_a(entry_point), debugstr_a(target), sflags, eflags, pump, shader,
226 error_messages, hresult);
227
228 if (pump)
229 FIXME("Unimplemented ID3DX11ThreadPump handling.\n");
230
231 return D3DCompile(data, data_size, filename, defines, include, entry_point, target,
233}
234
236 ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags,
238{
239 WCHAR filename_w[MAX_PATH];
240
241 TRACE("filename %s, defines %p, include %p, entry_point %s, target %s, sflags %#x, "
242 "eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
244 sflags, eflags, pump, shader, error_messages, hresult);
245
246 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, ARRAY_SIZE(filename_w));
247
248 return D3DX11CompileFromFileW(filename_w, defines, include, entry_point, target,
249 sflags, eflags, pump, shader, error_messages, hresult);
250}
251
253 ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags,
255{
256 HRESULT hr;
257
258 TRACE("filename %s, defines %p, include %p, entry_point %s, target %s, sflags %#x, "
259 "eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
261 sflags, eflags, pump, shader, error_messages, hresult);
262
263 if (pump)
264 FIXME("Unimplemented ID3DX11ThreadPump handling.\n");
265
266 if (!include)
268
270 if (hresult)
271 *hresult = hr;
272
273 return hr;
274}
275
277{
278 struct asyncdataloader *object;
279
280 TRACE("data %p, data_size %Iu, loader %p.\n", data, data_size, loader);
281
282 if (!data || !loader)
283 return E_FAIL;
284
285 object = calloc(1, sizeof(*object));
286 if (!object)
287 return E_OUTOFMEMORY;
288
289 object->ID3DX11DataLoader_iface.lpVtbl = &memorydataloadervtbl;
290 object->data = (void *)data;
291 object->size = data_size;
292
293 *loader = &object->ID3DX11DataLoader_iface;
294
295 return S_OK;
296}
297
299{
300 WCHAR *filename_w;
301 HRESULT hr;
302 int len;
303
304 TRACE("filename %s, loader %p.\n", debugstr_a(filename), loader);
305
306 if (!filename || !loader)
307 return E_FAIL;
308
310 filename_w = malloc(len * sizeof(*filename_w));
311 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
312
314
315 free(filename_w);
316
317 return hr;
318}
319
321{
322 struct asyncdataloader *object;
323
324 TRACE("filename %s, loader %p.\n", debugstr_w(filename), loader);
325
326 if (!filename || !loader)
327 return E_FAIL;
328
329 object = calloc(1, sizeof(*object));
330 if (!object)
331 return E_OUTOFMEMORY;
332
333 object->ID3DX11DataLoader_iface.lpVtbl = &filedataloadervtbl;
334 object->u.file.path = malloc((lstrlenW(filename) + 1) * sizeof(WCHAR));
335 if (!object->u.file.path)
336 {
337 free(object);
338 return E_OUTOFMEMORY;
339 }
340 lstrcpyW(object->u.file.path, filename);
341 object->data = NULL;
342 object->size = 0;
343
344 *loader = &object->ID3DX11DataLoader_iface;
345
346 return S_OK;
347}
348
350{
351 struct asyncdataloader *object;
352 HRSRC rsrc;
353
354 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_a(resource), loader);
355
356 if (!loader)
357 return E_FAIL;
358
359 object = calloc(1, sizeof(*object));
360 if (!object)
361 return E_OUTOFMEMORY;
362
363 if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA)))
364 {
365 WARN("Failed to find resource.\n");
366 free(object);
368 }
369
370 object->ID3DX11DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
371 object->u.resource.module = module;
372 object->u.resource.rsrc = rsrc;
373 object->data = NULL;
374 object->size = 0;
375
376 *loader = &object->ID3DX11DataLoader_iface;
377
378 return S_OK;
379}
380
382{
383 struct asyncdataloader *object;
384 HRSRC rsrc;
385
386 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_w(resource), loader);
387
388 if (!loader)
389 return E_FAIL;
390
391 object = calloc(1, sizeof(*object));
392 if (!object)
393 return E_OUTOFMEMORY;
394
395 if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
396 {
397 WARN("Failed to find resource.\n");
398 free(object);
400 }
401
402 object->ID3DX11DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
403 object->u.resource.module = module;
404 object->u.resource.rsrc = rsrc;
405 object->data = NULL;
406 object->size = 0;
407
408 *loader = &object->ID3DX11DataLoader_iface;
409
410 return S_OK;
411}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define D3D_COMPILE_STANDARD_FILE_INCLUDE
Definition: d3dcompiler.h:85
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: asm.c:31
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude UINT ID3DBlob ID3DBlob ** error_messages
Definition: asm.c:32
static SIZE_T const char const D3D_SHADER_MACRO * defines
Definition: asm.c:31
HRESULT WINAPI D3DCompile(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages)
Definition: compiler.c:639
HRESULT WINAPI D3DCompileFromFile(const WCHAR *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT flags1, UINT flags2, ID3DBlob **code, ID3DBlob **errors)
Definition: compiler.c:743
@ D3DX11_ERR_INVALID_DATA
Definition: d3dx11.h:44
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
HRESULT hr
Definition: delayimp.cpp:582
static HRESULT WINAPI filedataloader_Destroy(ID3DX10DataLoader *iface)
Definition: async.c:156
static HRESULT WINAPI resourcedataloader_Destroy(ID3DX10DataLoader *iface)
Definition: async.c:261
static const ID3DX10DataLoaderVtbl resourcedataloadervtbl
Definition: async.c:272
static HRESULT WINAPI memorydataloader_Load(ID3DX10DataLoader *iface)
Definition: async.c:56
static HRESULT WINAPI filedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
Definition: async.c:141
static const ID3DX10DataLoaderVtbl memorydataloadervtbl
Definition: async.c:84
static HRESULT WINAPI memorydataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
Definition: async.c:62
static HRESULT WINAPI memorydataloader_Destroy(ID3DX10DataLoader *iface)
Definition: async.c:74
static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface)
Definition: async.c:121
static HRESULT WINAPI resourcedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size)
Definition: async.c:246
static const ID3DX10DataLoaderVtbl filedataloadervtbl
Definition: async.c:169
static HRESULT WINAPI resourcedataloader_Load(ID3DX10DataLoader *iface)
Definition: async.c:233
HRESULT WINAPI D3DX11CreateAsyncFileLoaderA(const char *filename, ID3DX11DataLoader **loader)
Definition: async.c:298
HRESULT WINAPI D3DX11CompileFromFileA(const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags, ID3DX11ThreadPump *pump, ID3D10Blob **shader, ID3D10Blob **error_messages, HRESULT *hresult)
Definition: async.c:235
HRESULT WINAPI D3DX11CompileFromFileW(const WCHAR *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags, ID3DX11ThreadPump *pump, ID3D10Blob **shader, ID3D10Blob **error_messages, HRESULT *hresult)
Definition: async.c:252
HRESULT WINAPI D3DX11CompileFromMemory(const char *data, SIZE_T data_size, const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags, ID3DX11ThreadPump *pump, ID3D10Blob **shader, ID3D10Blob **error_messages, HRESULT *hresult)
Definition: async.c:217
HRESULT WINAPI D3DX11CreateAsyncMemoryLoader(const void *data, SIZE_T data_size, ID3DX11DataLoader **loader)
Definition: async.c:276
HRESULT WINAPI D3DX11CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX11DataLoader **loader)
Definition: async.c:320
HRESULT WINAPI D3DX11CreateAsyncResourceLoaderA(HMODULE module, const char *resource, ID3DX11DataLoader **loader)
Definition: async.c:349
HRESULT WINAPI D3DX11CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *resource, ID3DX11DataLoader **loader)
Definition: async.c:381
static struct asyncdataloader * impl_from_ID3DX11DataLoader(ID3DX11DataLoader *iface)
Definition: async.c:46
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define lstrcpyW
Definition: compat.h:749
#define MultiByteToWideChar
Definition: compat.h:110
#define FILE_SHARE_READ
Definition: compat.h:136
#define lstrlenW
Definition: compat.h:750
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HRSRC WINAPI FindResourceA(HMODULE hModule, LPCSTR name, LPCSTR type)
Definition: res.c:155
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
return ret
Definition: mutex.c:147
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLuint shader
Definition: glext.h:6030
GLenum GLsizei len
Definition: glext.h:6722
unsigned int UINT
Definition: sysinfo.c:13
#define S_OK
Definition: intsafe.h:52
const char * filename
Definition: ioapi.h:137
#define debugstr_a
Definition: kernel32.h:31
#define debugstr_w
Definition: kernel32.h:32
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
short WCHAR
Definition: pedump.c:58
#define RT_RCDATA
Definition: pedump.c:372
#define calloc
Definition: rosglue.h:14
#define TRACE(s)
Definition: solgame.cpp:4
struct asyncdataloader::@274::@276 resource
union asyncdataloader::@274 u
WCHAR * path
Definition: async.c:39
HRSRC rsrc
Definition: async.c:44
struct asyncdataloader::@274::@275 file
HMODULE module
Definition: async.c:43
ID3DX11DataLoader ID3DX11DataLoader_iface
Definition: async.c:28
SIZE_T size
Definition: async.c:43
void * data
Definition: async.c:47
Definition: fci.c:123
Definition: loader.c:72
Definition: tools.h:99
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define WINAPI
Definition: msvc.h:6
#define D3D11_ERROR_FILE_NOT_FOUND
Definition: winerror.h:7168