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
20 #include "wine/port.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
;
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
);
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
);
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
);
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
);
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
);
112 return E_OUTOFMEMORY
;
115 ret
= ReadFile(file
, data
, size
, &read_len
, NULL
);
119 ERR("Failed to read file contents.\n");
120 HeapFree(GetProcessHeap(), 0, data
);
124 HeapFree(GetProcessHeap(), 0, loader
->data
);
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
);
140 *data
= loader
->data
;
141 *size
= loader
->size
;
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
);
159 static const ID3DX10DataLoaderVtbl filedataloadervtbl
=
162 filedataloader_Decompress
,
163 filedataloader_Destroy
166 static HRESULT WINAPI
resourcedataloader_Load(ID3DX10DataLoader
*iface
)
168 struct asyncdataloader
*loader
= impl_from_ID3DX10DataLoader(iface
);
171 TRACE("iface %p.\n", iface
);
176 hglobal
= LoadResource(loader
->u
.resource
.module
, loader
->u
.resource
.rsrc
);
179 ERR("Failed to load resource.\n");
183 loader
->data
= LockResource(hglobal
);
184 loader
->size
= SizeofResource(loader
->u
.resource
.module
, loader
->u
.resource
.rsrc
);
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
);
198 *data
= loader
->data
;
199 *size
= loader
->size
;
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
);
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
);
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
);
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
);
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
)
273 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*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
;
286 HRESULT WINAPI
D3DX10CreateAsyncFileLoaderA(const char *filename
, ID3DX10DataLoader
**loader
)
292 TRACE("filename %s, loader %p.\n", debugstr_a(filename
), loader
);
294 if (!filename
|| !loader
)
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
);
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
)
317 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*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
);
332 *loader
= &object
->ID3DX10DataLoader_iface
;
337 HRESULT WINAPI
D3DX10CreateAsyncResourceLoaderA(HMODULE module
, const char *resource
, ID3DX10DataLoader
**loader
)
339 struct asyncdataloader
*object
;
342 TRACE("module %p, resource %s, loader %p.\n", module
, debugstr_a(resource
), loader
);
347 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*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
;
364 *loader
= &object
->ID3DX10DataLoader_iface
;
369 HRESULT WINAPI
D3DX10CreateAsyncResourceLoaderW(HMODULE module
, const WCHAR
*resource
, ID3DX10DataLoader
**loader
)
371 struct asyncdataloader
*object
;
374 TRACE("module %p, resource %s, loader %p.\n", module
, debugstr_w(resource
), loader
);
379 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*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
;
396 *loader
= &object
->ID3DX10DataLoader_iface
;