mshtml: Added IDOMEvent::pageX and pageY properties implementation.
[wine.git] / dlls / d3dx11_43 / async.c
blobece13e99c2d0931f1646777bc21cee2fd378b752
1 /*
2 * Copyright 2016 Matteo Bruni for CodeWeavers
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 "d3dx11.h"
22 #include "d3dcompiler.h"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
29 struct asyncdataloader
31 ID3DX11DataLoader ID3DX11DataLoader_iface;
33 union
35 struct
37 WCHAR *path;
38 } file;
39 struct
41 HMODULE module;
42 HRSRC rsrc;
43 } resource;
44 } u;
45 void *data;
46 SIZE_T size;
49 static inline struct asyncdataloader *impl_from_ID3DX11DataLoader(ID3DX11DataLoader *iface)
51 return CONTAINING_RECORD(iface, struct asyncdataloader, ID3DX11DataLoader_iface);
54 static HRESULT WINAPI memorydataloader_Load(ID3DX11DataLoader *iface)
56 TRACE("iface %p.\n", iface);
57 return S_OK;
60 static HRESULT WINAPI memorydataloader_Decompress(ID3DX11DataLoader *iface, void **data, SIZE_T *size)
62 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
64 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
66 *data = loader->data;
67 *size = loader->size;
69 return S_OK;
72 static HRESULT WINAPI memorydataloader_Destroy(ID3DX11DataLoader *iface)
74 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
76 TRACE("iface %p.\n", iface);
78 HeapFree(GetProcessHeap(), 0, loader);
79 return S_OK;
82 static const ID3DX11DataLoaderVtbl memorydataloadervtbl =
84 memorydataloader_Load,
85 memorydataloader_Decompress,
86 memorydataloader_Destroy
89 static HRESULT WINAPI filedataloader_Load(ID3DX11DataLoader *iface)
91 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
92 DWORD size, read_len;
93 HANDLE file;
94 void *data;
95 BOOL ret;
97 TRACE("iface %p.\n", iface);
99 /* Always buffer file contents, even if Load() was already called. */
100 file = CreateFileW(loader->u.file.path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
101 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
102 if (file == INVALID_HANDLE_VALUE)
103 return D3D11_ERROR_FILE_NOT_FOUND;
105 size = GetFileSize(file, NULL);
106 data = HeapAlloc(GetProcessHeap(), 0, size);
107 if (!data)
109 CloseHandle(file);
110 return E_OUTOFMEMORY;
113 ret = ReadFile(file, data, size, &read_len, NULL);
114 CloseHandle(file);
115 if (!ret)
117 ERR("Failed to read file contents.\n");
118 HeapFree(GetProcessHeap(), 0, data);
119 return E_FAIL;
122 HeapFree(GetProcessHeap(), 0, loader->data);
123 loader->data = data;
124 loader->size = size;
126 return S_OK;
129 static HRESULT WINAPI filedataloader_Decompress(ID3DX11DataLoader *iface, void **data, SIZE_T *size)
131 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
133 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
135 if (!loader->data)
136 return E_FAIL;
138 *data = loader->data;
139 *size = loader->size;
141 return S_OK;
144 static HRESULT WINAPI filedataloader_Destroy(ID3DX11DataLoader *iface)
146 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
148 TRACE("iface %p.\n", iface);
150 HeapFree(GetProcessHeap(), 0, loader->u.file.path);
151 HeapFree(GetProcessHeap(), 0, loader->data);
152 HeapFree(GetProcessHeap(), 0, loader);
154 return S_OK;
157 static const ID3DX11DataLoaderVtbl filedataloadervtbl =
159 filedataloader_Load,
160 filedataloader_Decompress,
161 filedataloader_Destroy
164 static HRESULT WINAPI resourcedataloader_Load(ID3DX11DataLoader *iface)
166 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
167 HGLOBAL hglobal;
169 TRACE("iface %p.\n", iface);
171 if (loader->data)
172 return S_OK;
174 hglobal = LoadResource(loader->u.resource.module, loader->u.resource.rsrc);
175 if (!hglobal)
177 ERR("Failed to load resource.\n");
178 return E_FAIL;
181 loader->data = LockResource(hglobal);
182 loader->size = SizeofResource(loader->u.resource.module, loader->u.resource.rsrc);
184 return S_OK;
187 static HRESULT WINAPI resourcedataloader_Decompress(ID3DX11DataLoader *iface, void **data, SIZE_T *size)
189 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
191 TRACE("iface %p, data %p, size %p.\n", iface, data, size);
193 if (!loader->data)
194 return E_FAIL;
196 *data = loader->data;
197 *size = loader->size;
199 return S_OK;
202 static HRESULT WINAPI resourcedataloader_Destroy(ID3DX11DataLoader *iface)
204 struct asyncdataloader *loader = impl_from_ID3DX11DataLoader(iface);
206 TRACE("iface %p.\n", iface);
208 HeapFree(GetProcessHeap(), 0, loader);
210 return S_OK;
213 static const ID3DX11DataLoaderVtbl resourcedataloadervtbl =
215 resourcedataloader_Load,
216 resourcedataloader_Decompress,
217 resourcedataloader_Destroy
220 HRESULT WINAPI D3DX11CompileFromMemory(const char *data, SIZE_T data_size, const char *filename,
221 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point,
222 const char *target, UINT sflags, UINT eflags, ID3DX11ThreadPump *pump, ID3D10Blob **shader,
223 ID3D10Blob **error_messages, HRESULT *hresult)
225 TRACE("data %s, data_size %lu, filename %s, defines %p, include %p, entry_point %s, target %s, "
226 "sflags %#x, eflags %#x, pump %p, shader %p, error_messages %p, hresult %p.\n",
227 debugstr_an(data, data_size), data_size, debugstr_a(filename), defines, include,
228 debugstr_a(entry_point), debugstr_a(target), sflags, eflags, pump, shader,
229 error_messages, hresult);
231 if (pump)
232 FIXME("Unimplemented ID3DX11ThreadPump handling.\n");
234 return D3DCompile(data, data_size, filename, defines, include, entry_point, target,
235 sflags, eflags, shader, error_messages);
238 HRESULT WINAPI D3DX11CompileFromFileA(const char *filename, const D3D10_SHADER_MACRO *defines,
239 ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags,
240 ID3DX11ThreadPump *pump, ID3D10Blob **shader, ID3D10Blob **error_messages, HRESULT *hresult)
242 FIXME("filename %s, defines %p, include %p, entry_point %s, target %s, sflags %#x, "
243 "eflags %#x, pump %p, shader %p, error_messages %p, hresult %p stub.\n",
244 debugstr_a(filename), defines, include, debugstr_a(entry_point), debugstr_a(target),
245 sflags, eflags, pump, shader, error_messages, hresult);
247 return E_NOTIMPL;
250 HRESULT WINAPI D3DX11CompileFromFileW(const WCHAR *filename, const D3D10_SHADER_MACRO *defines,
251 ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags,
252 ID3DX11ThreadPump *pump, ID3D10Blob **shader, ID3D10Blob **error_messages, HRESULT *hresult)
254 FIXME("filename %s, defines %p, include %p, entry_point %s, target %s, sflags %#x, "
255 "eflags %#x, pump %p, shader %p, error_messages %p, hresult %p stub.\n",
256 debugstr_w(filename), defines, include, debugstr_a(entry_point), debugstr_a(target),
257 sflags, eflags, pump, shader, error_messages, hresult);
259 return E_NOTIMPL;
262 HRESULT WINAPI D3DX11CreateAsyncMemoryLoader(const void *data, SIZE_T data_size, ID3DX11DataLoader **loader)
264 struct asyncdataloader *object;
266 TRACE("data %p, data_size %lu, loader %p.\n", data, data_size, loader);
268 if (!data || !loader)
269 return E_FAIL;
271 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
272 if (!object)
273 return E_OUTOFMEMORY;
275 object->ID3DX11DataLoader_iface.lpVtbl = &memorydataloadervtbl;
276 object->data = (void *)data;
277 object->size = data_size;
279 *loader = &object->ID3DX11DataLoader_iface;
281 return S_OK;
284 HRESULT WINAPI D3DX11CreateAsyncFileLoaderA(const char *filename, ID3DX11DataLoader **loader)
286 WCHAR *filename_w;
287 HRESULT hr;
288 int len;
290 TRACE("filename %s, loader %p.\n", debugstr_a(filename), loader);
292 if (!filename || !loader)
293 return E_FAIL;
295 len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0);
296 filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*filename_w));
297 MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
299 hr = D3DX11CreateAsyncFileLoaderW(filename_w, loader);
301 HeapFree(GetProcessHeap(), 0, filename_w);
303 return hr;
306 HRESULT WINAPI D3DX11CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX11DataLoader **loader)
308 struct asyncdataloader *object;
310 TRACE("filename %s, loader %p.\n", debugstr_w(filename), loader);
312 if (!filename || !loader)
313 return E_FAIL;
315 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
316 if (!object)
317 return E_OUTOFMEMORY;
319 object->ID3DX11DataLoader_iface.lpVtbl = &filedataloadervtbl;
320 object->u.file.path = HeapAlloc(GetProcessHeap(), 0, (strlenW(filename) + 1) * sizeof(WCHAR));
321 if (!object->u.file.path)
323 HeapFree(GetProcessHeap(), 0, object);
324 return E_OUTOFMEMORY;
326 strcpyW(object->u.file.path, filename);
327 object->data = NULL;
328 object->size = 0;
330 *loader = &object->ID3DX11DataLoader_iface;
332 return S_OK;
335 HRESULT WINAPI D3DX11CreateAsyncResourceLoaderA(HMODULE module, const char *resource, ID3DX11DataLoader **loader)
337 struct asyncdataloader *object;
338 HRSRC rsrc;
340 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_a(resource), loader);
342 if (!loader)
343 return E_FAIL;
345 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
346 if (!object)
347 return E_OUTOFMEMORY;
349 if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA)))
351 ERR("Failed to find resource.\n");
352 HeapFree(GetProcessHeap(), 0, object);
353 return D3DX11_ERR_INVALID_DATA;
356 object->ID3DX11DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
357 object->u.resource.module = module;
358 object->u.resource.rsrc = rsrc;
359 object->data = NULL;
360 object->size = 0;
362 *loader = &object->ID3DX11DataLoader_iface;
364 return S_OK;
367 HRESULT WINAPI D3DX11CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *resource, ID3DX11DataLoader **loader)
369 struct asyncdataloader *object;
370 HRSRC rsrc;
372 TRACE("module %p, resource %s, loader %p.\n", module, debugstr_w(resource), loader);
374 if (!loader)
375 return E_FAIL;
377 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
378 if (!object)
379 return E_OUTOFMEMORY;
381 if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA)))
383 ERR("Failed to find resource.\n");
384 HeapFree(GetProcessHeap(), 0, object);
385 return D3DX11_ERR_INVALID_DATA;
388 object->ID3DX11DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
389 object->u.resource.module = module;
390 object->u.resource.rsrc = rsrc;
391 object->data = NULL;
392 object->size = 0;
394 *loader = &object->ID3DX11DataLoader_iface;
396 return S_OK;