- use CRT allocators - share data loading code - implement D3DX10CreateAsyncTextureInfoProcessor
From: Piotr Caban piotr@codeweavers.com
--- dlls/d3dx10_43/async.c | 36 ++++++++++++++++++------------------ dlls/d3dx10_43/compiler.c | 9 ++++----- dlls/d3dx10_43/font.c | 31 +++++++++++++++---------------- dlls/d3dx10_43/mesh.c | 5 ++--- dlls/d3dx10_43/sprite.c | 5 ++--- dlls/d3dx10_43/texture.c | 21 ++++++++++----------- 6 files changed, 51 insertions(+), 56 deletions(-)
diff --git a/dlls/d3dx10_43/async.c b/dlls/d3dx10_43/async.c index 716eb7f44fb..5a8ba77db87 100644 --- a/dlls/d3dx10_43/async.c +++ b/dlls/d3dx10_43/async.c @@ -73,7 +73,7 @@ static HRESULT WINAPI memorydataloader_Destroy(ID3DX10DataLoader *iface)
TRACE("iface %p.\n", iface);
- HeapFree(GetProcessHeap(), 0, loader); + free(loader); return S_OK; }
@@ -101,7 +101,7 @@ static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface) return D3D10_ERROR_FILE_NOT_FOUND;
size = GetFileSize(file, NULL); - data = HeapAlloc(GetProcessHeap(), 0, size); + data = malloc(size); if (!data) { CloseHandle(file); @@ -113,11 +113,11 @@ static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface) if (!ret) { WARN("Failed to read file contents.\n"); - HeapFree(GetProcessHeap(), 0, data); + free(data); return E_FAIL; }
- HeapFree(GetProcessHeap(), 0, loader->data); + free(loader->data); loader->data = data; loader->size = size;
@@ -145,9 +145,9 @@ static HRESULT WINAPI filedataloader_Destroy(ID3DX10DataLoader *iface)
TRACE("iface %p.\n", iface);
- HeapFree(GetProcessHeap(), 0, loader->u.file.path); - HeapFree(GetProcessHeap(), 0, loader->data); - HeapFree(GetProcessHeap(), 0, loader); + free(loader->u.file.path); + free(loader->data); + free(loader);
return S_OK; } @@ -203,7 +203,7 @@ static HRESULT WINAPI resourcedataloader_Destroy(ID3DX10DataLoader *iface)
TRACE("iface %p.\n", iface);
- HeapFree(GetProcessHeap(), 0, loader); + free(loader);
return S_OK; } @@ -266,7 +266,7 @@ HRESULT WINAPI D3DX10CreateAsyncMemoryLoader(const void *data, SIZE_T data_size, if (!data || !loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
@@ -291,12 +291,12 @@ HRESULT WINAPI D3DX10CreateAsyncFileLoaderA(const char *filename, ID3DX10DataLoa return E_FAIL;
len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0); - filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*filename_w)); + filename_w = malloc(len * sizeof(*filename_w)); MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
hr = D3DX10CreateAsyncFileLoaderW(filename_w, loader);
- HeapFree(GetProcessHeap(), 0, filename_w); + free(filename_w);
return hr; } @@ -310,15 +310,15 @@ HRESULT WINAPI D3DX10CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX10DataLo if (!filename || !loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
object->ID3DX10DataLoader_iface.lpVtbl = &filedataloadervtbl; - object->u.file.path = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1) * sizeof(WCHAR)); + object->u.file.path = malloc((lstrlenW(filename) + 1) * sizeof(WCHAR)); if (!object->u.file.path) { - HeapFree(GetProcessHeap(), 0, object); + free(object); return E_OUTOFMEMORY; } lstrcpyW(object->u.file.path, filename); @@ -340,7 +340,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *reso if (!loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
@@ -349,7 +349,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *reso if (!rsrc) { WARN("Failed to find resource.\n"); - HeapFree(GetProcessHeap(), 0, object); + free(object); return D3DX10_ERR_INVALID_DATA; }
@@ -374,7 +374,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res if (!loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
@@ -383,7 +383,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res if (!rsrc) { WARN("Failed to find resource.\n"); - HeapFree(GetProcessHeap(), 0, object); + free(object); return D3DX10_ERR_INVALID_DATA; }
diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index 91a99110d0b..9ae3fe93f85 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -18,7 +18,6 @@ */
#include "wine/debug.h" -#include "wine/heap.h"
#define COBJMACROS
@@ -113,13 +112,13 @@ HRESULT WINAPI D3DX10CreateEffectFromFileA(const char *filename, const D3D10_SHA return E_INVALIDARG;
len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0); - if (!(filenameW = heap_alloc(len * sizeof(*filenameW)))) + if (!(filenameW = malloc(len * sizeof(*filenameW)))) return E_OUTOFMEMORY; MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, len);
hr = D3DX10CreateEffectFromFileW(filenameW, defines, include, profile, shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); - heap_free(filenameW); + free(filenameW);
return hr; } @@ -198,13 +197,13 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso if (filenameW) { len = WideCharToMultiByte(CP_ACP, 0, filenameW, -1, NULL, 0, NULL, NULL); - if (!(filename = heap_alloc(len))) + if (!(filename = malloc(len))) return E_OUTOFMEMORY; WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, len, NULL, NULL); }
hr = D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile, shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); - heap_free(filename); + free(filename); return hr; } diff --git a/dlls/d3dx10_43/font.c b/dlls/d3dx10_43/font.c index 1589c3a0eef..09560363312 100644 --- a/dlls/d3dx10_43/font.c +++ b/dlls/d3dx10_43/font.c @@ -21,7 +21,6 @@ #include "d3dx10.h"
#include "wine/debug.h" -#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -82,7 +81,7 @@ static ULONG WINAPI d3dx_font_Release(ID3DX10Font *iface) DeleteObject(font->hfont); DeleteDC(font->hdc); ID3D10Device_Release(font->device); - heap_free(font); + free(font); } return refcount; } @@ -179,14 +178,14 @@ static HRESULT WINAPI d3dx_font_PreloadCharacters(ID3DX10Font *iface, UINT first return S_OK;
count = last - first + 1; - indices = heap_alloc(count * sizeof(*indices)); + indices = malloc(count * sizeof(*indices)); if (!indices) return E_OUTOFMEMORY;
- chars = heap_alloc(count * sizeof(*chars)); + chars = malloc(count * sizeof(*chars)); if (!chars) { - heap_free(indices); + free(indices); return E_OUTOFMEMORY; }
@@ -208,8 +207,8 @@ static HRESULT WINAPI d3dx_font_PreloadCharacters(ID3DX10Font *iface, UINT first } ID3DX10Font_PreloadGlyphs(iface, start, end);
- heap_free(chars); - heap_free(indices); + free(chars); + free(indices);
return S_OK; } @@ -237,14 +236,14 @@ static HRESULT WINAPI d3dx_font_PreloadTextA(ID3DX10Font *iface, const char *str
countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0);
- if (!(wstr = heap_alloc(countW * sizeof(*wstr)))) + if (!(wstr = malloc(countW * sizeof(*wstr)))) return E_OUTOFMEMORY;
MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW);
hr = ID3DX10Font_PreloadTextW(iface, wstr, count < 0 ? countW - 1 : countW);
- heap_free(wstr); + free(wstr);
return hr; } @@ -266,7 +265,7 @@ static HRESULT WINAPI d3dx_font_PreloadTextW(ID3DX10Font *iface, const WCHAR *st if (count < 0) count = lstrlenW(string);
- indices = heap_alloc(count * sizeof(*indices)); + indices = malloc(count * sizeof(*indices)); if (!indices) return E_OUTOFMEMORY;
@@ -275,7 +274,7 @@ static HRESULT WINAPI d3dx_font_PreloadTextW(ID3DX10Font *iface, const WCHAR *st for (i = 0; i < count; ++i) ID3DX10Font_PreloadGlyphs(iface, indices[i], indices[i]);
- heap_free(indices); + free(indices);
return S_OK; } @@ -296,7 +295,7 @@ static INT WINAPI d3dx_font_DrawTextA(ID3DX10Font *iface, ID3DX10Sprite *sprite, if (!(countW = MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, NULL, 0))) return 0;
- if (!(wstr = heap_alloc_zero(countW * sizeof(*wstr)))) + if (!(wstr = calloc(countW, sizeof(*wstr)))) return 0;
MultiByteToWideChar(CP_ACP, 0, string, count < 0 ? -1 : count, wstr, countW); @@ -304,7 +303,7 @@ static INT WINAPI d3dx_font_DrawTextA(ID3DX10Font *iface, ID3DX10Sprite *sprite, ret = ID3DX10Font_DrawTextW(iface, sprite, wstr, count < 0 ? countW - 1 : countW, rect, format, color);
- heap_free(wstr); + free(wstr);
return ret; } @@ -430,13 +429,13 @@ HRESULT WINAPI D3DX10CreateFontIndirectW(ID3D10Device *device, const D3DX10_FONT
*font = NULL;
- if (!(object = heap_alloc_zero(sizeof(*object)))) + if (!(object = calloc(1, sizeof(*object)))) return E_OUTOFMEMORY;
object->hdc = CreateCompatibleDC(NULL); if (!object->hdc) { - heap_free(object); + free(object); return E_FAIL; }
@@ -445,7 +444,7 @@ HRESULT WINAPI D3DX10CreateFontIndirectW(ID3D10Device *device, const D3DX10_FONT if (!object->hfont) { DeleteDC(object->hdc); - heap_free(object); + free(object); return E_FAIL; } SelectObject(object->hdc, object->hfont); diff --git a/dlls/d3dx10_43/mesh.c b/dlls/d3dx10_43/mesh.c index 7b8b0c80956..5966661573d 100644 --- a/dlls/d3dx10_43/mesh.c +++ b/dlls/d3dx10_43/mesh.c @@ -21,7 +21,6 @@ #include "d3dx10.h"
#include "wine/debug.h" -#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -72,7 +71,7 @@ static ULONG STDMETHODCALLTYPE d3dx10_mesh_Release(ID3DX10Mesh *iface) TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
if (!refcount) - heap_free(mesh); + free(mesh);
return refcount; } @@ -366,7 +365,7 @@ HRESULT WINAPI D3DX10CreateMesh(ID3D10Device *device, const D3D10_INPUT_ELEMENT_
*mesh = NULL;
- if (!(object = heap_alloc_zero(sizeof(*object)))) + if (!(object = calloc(1, sizeof(*object)))) return E_OUTOFMEMORY;
object->ID3DX10Mesh_iface.lpVtbl = &d3dx10_mesh_vtbl; diff --git a/dlls/d3dx10_43/sprite.c b/dlls/d3dx10_43/sprite.c index 307bb575d7a..6feae868a44 100644 --- a/dlls/d3dx10_43/sprite.c +++ b/dlls/d3dx10_43/sprite.c @@ -21,7 +21,6 @@ #include "d3dx10.h"
#include "wine/debug.h" -#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -79,7 +78,7 @@ static ULONG WINAPI d3dx10_sprite_Release(ID3DX10Sprite *iface) if (!refcount) { ID3D10Device_Release(sprite->device); - heap_free(sprite); + free(sprite); }
return refcount; @@ -209,7 +208,7 @@ HRESULT WINAPI D3DX10CreateSprite(ID3D10Device *device, UINT size, ID3DX10Sprite
*sprite = NULL;
- if (!(object = heap_alloc_zero(sizeof(*object)))) + if (!(object = calloc(1, sizeof(*object)))) return E_OUTOFMEMORY;
object->ID3DX10Sprite_iface.lpVtbl = &d3dx10_sprite_vtbl; diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index dd3ad1497d5..41f9723de6b 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -17,7 +17,6 @@ */
#include "wine/debug.h" -#include "wine/heap.h"
#define COBJMACROS
@@ -313,7 +312,7 @@ static HRESULT load_file(const WCHAR *filename, void **buffer, DWORD *size) goto done; }
- *buffer = heap_alloc(*size); + *buffer = malloc(*size); if (!*buffer) { hr = E_OUTOFMEMORY; @@ -335,7 +334,7 @@ static HRESULT load_file(const WCHAR *filename, void **buffer, DWORD *size) done: if (FAILED(hr)) { - heap_free(*buffer); + free(*buffer); *buffer = NULL; } if (file != INVALID_HANDLE_VALUE) @@ -375,14 +374,14 @@ HRESULT WINAPI D3DX10GetImageInfoFromFileA(const char *src_file, ID3DX10ThreadPu if (!str_len) return HRESULT_FROM_WIN32(GetLastError());
- buffer = heap_alloc(str_len * sizeof(*buffer)); + buffer = malloc(str_len * sizeof(*buffer)); if (!buffer) return E_OUTOFMEMORY;
MultiByteToWideChar(CP_ACP, 0, src_file, -1, buffer, str_len); hr = D3DX10GetImageInfoFromFileW(buffer, pump, info, result);
- heap_free(buffer); + free(buffer);
return hr; } @@ -404,7 +403,7 @@ HRESULT WINAPI D3DX10GetImageInfoFromFileW(const WCHAR *src_file, ID3DX10ThreadP
hr = D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result);
- heap_free(buffer); + free(buffer);
return hr; } @@ -589,13 +588,13 @@ HRESULT WINAPI D3DX10CreateTextureFromFileA(ID3D10Device *device, const char *sr if (!(str_len = MultiByteToWideChar(CP_ACP, 0, src_file, -1, NULL, 0))) return HRESULT_FROM_WIN32(GetLastError());
- if (!(buffer = heap_alloc(str_len * sizeof(*buffer)))) + if (!(buffer = malloc(str_len * sizeof(*buffer)))) return E_OUTOFMEMORY;
MultiByteToWideChar(CP_ACP, 0, src_file, -1, buffer, str_len); hr = D3DX10CreateTextureFromFileW(device, buffer, load_info, pump, texture, hresult);
- heap_free(buffer); + free(buffer);
return hr; } @@ -618,7 +617,7 @@ HRESULT WINAPI D3DX10CreateTextureFromFileW(ID3D10Device *device, const WCHAR *s
hr = D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult);
- heap_free(buffer); + free(buffer);
return hr; } @@ -740,7 +739,7 @@ HRESULT WINAPI D3DX10CreateTextureFromMemory(ID3D10Device *device, const void *s stride = (width * get_bpp_from_format(img_info.Format) + 7) / 8; frame_size = stride * height;
- if (!(buffer = heap_alloc(frame_size))) + if (!(buffer = malloc(frame_size))) { hr = E_FAIL; goto end; @@ -813,7 +812,7 @@ end: IWICFormatConverter_Release(converter); if (dds_frame) IWICDdsFrameDecode_Release(dds_frame); - heap_free(buffer); + free(buffer); if (frame) IWICBitmapFrameDecode_Release(frame); if (decoder)
From: Piotr Caban piotr@codeweavers.com
--- dlls/d3dx11_43/async.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/dlls/d3dx11_43/async.c b/dlls/d3dx11_43/async.c index 8d947742b9d..074a8529e4e 100644 --- a/dlls/d3dx11_43/async.c +++ b/dlls/d3dx11_43/async.c @@ -72,7 +72,7 @@ static HRESULT WINAPI memorydataloader_Destroy(ID3DX11DataLoader *iface)
TRACE("iface %p.\n", iface);
- HeapFree(GetProcessHeap(), 0, loader); + free(loader); return S_OK; }
@@ -100,7 +100,7 @@ static HRESULT WINAPI filedataloader_Load(ID3DX11DataLoader *iface) return D3D11_ERROR_FILE_NOT_FOUND;
size = GetFileSize(file, NULL); - data = HeapAlloc(GetProcessHeap(), 0, size); + data = malloc(size); if (!data) { CloseHandle(file); @@ -112,11 +112,11 @@ static HRESULT WINAPI filedataloader_Load(ID3DX11DataLoader *iface) if (!ret) { ERR("Failed to read file contents.\n"); - HeapFree(GetProcessHeap(), 0, data); + free(data); return E_FAIL; }
- HeapFree(GetProcessHeap(), 0, loader->data); + free(loader->data); loader->data = data; loader->size = size;
@@ -144,9 +144,9 @@ static HRESULT WINAPI filedataloader_Destroy(ID3DX11DataLoader *iface)
TRACE("iface %p.\n", iface);
- HeapFree(GetProcessHeap(), 0, loader->u.file.path); - HeapFree(GetProcessHeap(), 0, loader->data); - HeapFree(GetProcessHeap(), 0, loader); + free(loader->u.file.path); + free(loader->data); + free(loader);
return S_OK; } @@ -202,7 +202,7 @@ static HRESULT WINAPI resourcedataloader_Destroy(ID3DX11DataLoader *iface)
TRACE("iface %p.\n", iface);
- HeapFree(GetProcessHeap(), 0, loader); + free(loader);
return S_OK; } @@ -282,7 +282,7 @@ HRESULT WINAPI D3DX11CreateAsyncMemoryLoader(const void *data, SIZE_T data_size, if (!data || !loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
@@ -307,12 +307,12 @@ HRESULT WINAPI D3DX11CreateAsyncFileLoaderA(const char *filename, ID3DX11DataLoa return E_FAIL;
len = MultiByteToWideChar(CP_ACP, 0, filename, -1, NULL, 0); - filename_w = HeapAlloc(GetProcessHeap(), 0, len * sizeof(*filename_w)); + filename_w = malloc(len * sizeof(*filename_w)); MultiByteToWideChar(CP_ACP, 0, filename, -1, filename_w, len);
hr = D3DX11CreateAsyncFileLoaderW(filename_w, loader);
- HeapFree(GetProcessHeap(), 0, filename_w); + free(filename_w);
return hr; } @@ -326,15 +326,15 @@ HRESULT WINAPI D3DX11CreateAsyncFileLoaderW(const WCHAR *filename, ID3DX11DataLo if (!filename || !loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
object->ID3DX11DataLoader_iface.lpVtbl = &filedataloadervtbl; - object->u.file.path = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(filename) + 1) * sizeof(WCHAR)); + object->u.file.path = malloc((lstrlenW(filename) + 1) * sizeof(WCHAR)); if (!object->u.file.path) { - HeapFree(GetProcessHeap(), 0, object); + free(object); return E_OUTOFMEMORY; } lstrcpyW(object->u.file.path, filename); @@ -356,14 +356,14 @@ HRESULT WINAPI D3DX11CreateAsyncResourceLoaderA(HMODULE module, const char *reso if (!loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA))) { WARN("Failed to find resource.\n"); - HeapFree(GetProcessHeap(), 0, object); + free(object); return D3DX11_ERR_INVALID_DATA; }
@@ -388,14 +388,14 @@ HRESULT WINAPI D3DX11CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res if (!loader) return E_FAIL;
- object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); + object = calloc(1, sizeof(*object)); if (!object) return E_OUTOFMEMORY;
if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))) { WARN("Failed to find resource.\n"); - HeapFree(GetProcessHeap(), 0, object); + free(object); return D3DX11_ERR_INVALID_DATA; }
From: Piotr Caban piotr@codeweavers.com
--- dlls/d3dx10_43/async.c | 38 +++++++++++++++--------- dlls/d3dx10_43/dxhelpers.h | 19 ++++++++++++ dlls/d3dx10_43/texture.c | 60 ++++---------------------------------- 3 files changed, 48 insertions(+), 69 deletions(-) create mode 100644 dlls/d3dx10_43/dxhelpers.h
diff --git a/dlls/d3dx10_43/async.c b/dlls/d3dx10_43/async.c index 5a8ba77db87..21fa437ac73 100644 --- a/dlls/d3dx10_43/async.c +++ b/dlls/d3dx10_43/async.c @@ -84,38 +84,48 @@ static const ID3DX10DataLoaderVtbl memorydataloadervtbl = memorydataloader_Destroy };
-static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface) +HRESULT load_file(const WCHAR *path, void **data, DWORD *size) { - struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface); - DWORD size, read_len; + DWORD read_len; HANDLE file; - void *data; BOOL ret;
- TRACE("iface %p.\n", iface); - - /* Always buffer file contents, even if Load() was already called. */ - file = CreateFileW(loader->u.file.path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, + file = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (file == INVALID_HANDLE_VALUE) return D3D10_ERROR_FILE_NOT_FOUND;
- size = GetFileSize(file, NULL); - data = malloc(size); - if (!data) + *size = GetFileSize(file, NULL); + *data = malloc(*size); + if (!*data) { CloseHandle(file); return E_OUTOFMEMORY; }
- ret = ReadFile(file, data, size, &read_len, NULL); + ret = ReadFile(file, *data, *size, &read_len, NULL); CloseHandle(file); - if (!ret) + if (!ret || read_len != *size) { WARN("Failed to read file contents.\n"); - free(data); + free(*data); return E_FAIL; } + return S_OK; +} + +static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface) +{ + struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface); + void *data; + DWORD size; + HRESULT hr; + + TRACE("iface %p.\n", iface); + + /* Always buffer file contents, even if Load() was already called. */ + if (FAILED((hr = load_file(loader->u.file.path, &data, &size)))) + return hr;
free(loader->data); loader->data = data; diff --git a/dlls/d3dx10_43/dxhelpers.h b/dlls/d3dx10_43/dxhelpers.h new file mode 100644 index 00000000000..9afc9bd901a --- /dev/null +++ b/dlls/d3dx10_43/dxhelpers.h @@ -0,0 +1,19 @@ +/* + * Copyright 2022 Piotr Caban + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +extern HRESULT load_file(const WCHAR *path, void **data, DWORD *size) DECLSPEC_HIDDEN; diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index 41f9723de6b..56258fdd60d 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -23,6 +23,7 @@ #include "d3d10_1.h" #include "d3dx10.h" #include "wincodec.h" +#include "dxhelpers.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -291,57 +292,6 @@ static DXGI_FORMAT get_d3dx10_dds_format(DXGI_FORMAT format) return format; }
-static HRESULT load_file(const WCHAR *filename, void **buffer, DWORD *size) -{ - HRESULT hr = S_OK; - DWORD bytes_read; - HANDLE file; - BOOL ret; - - file = CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); - if (file == INVALID_HANDLE_VALUE) - { - hr = HRESULT_FROM_WIN32(GetLastError()); - goto done; - } - - *size = GetFileSize(file, NULL); - if (*size == INVALID_FILE_SIZE) - { - hr = HRESULT_FROM_WIN32(GetLastError()); - goto done; - } - - *buffer = malloc(*size); - if (!*buffer) - { - hr = E_OUTOFMEMORY; - goto done; - } - - ret = ReadFile(file, *buffer, *size, &bytes_read, NULL); - if (!ret) - { - hr = HRESULT_FROM_WIN32(GetLastError()); - goto done; - } - if (bytes_read != *size) - { - hr = E_FAIL; - goto done; - } - -done: - if (FAILED(hr)) - { - free(*buffer); - *buffer = NULL; - } - if (file != INVALID_HANDLE_VALUE) - CloseHandle(file); - return hr; -} - static HRESULT load_resource(HMODULE module, HRSRC res_info, void **buffer, DWORD *size) { HGLOBAL resource; @@ -398,8 +348,8 @@ HRESULT WINAPI D3DX10GetImageInfoFromFileW(const WCHAR *src_file, ID3DX10ThreadP if (!src_file || !info) return E_FAIL;
- if (FAILED(load_file(src_file, &buffer, &size))) - return D3D10_ERROR_FILE_NOT_FOUND; + if (FAILED((hr = load_file(src_file, &buffer, &size)))) + return hr;
hr = D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result);
@@ -612,8 +562,8 @@ HRESULT WINAPI D3DX10CreateTextureFromFileW(ID3D10Device *device, const WCHAR *s if (!src_file || !texture) return E_FAIL;
- if (FAILED(load_file(src_file, &buffer, &size))) - return D3D10_ERROR_FILE_NOT_FOUND; + if (FAILED((hr = load_file(src_file, &buffer, &size)))) + return hr;
hr = D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult);
From: Piotr Caban piotr@codeweavers.com
--- dlls/d3dx10_43/async.c | 89 ++++++++++++++++++++++++++++---------- dlls/d3dx10_43/compiler.c | 34 +++------------ dlls/d3dx10_43/dxhelpers.h | 4 ++ dlls/d3dx10_43/texture.c | 70 +++++------------------------- 4 files changed, 85 insertions(+), 112 deletions(-)
diff --git a/dlls/d3dx10_43/async.c b/dlls/d3dx10_43/async.c index 21fa437ac73..33abd11eed6 100644 --- a/dlls/d3dx10_43/async.c +++ b/dlls/d3dx10_43/async.c @@ -41,7 +41,7 @@ struct asyncdataloader } resource; } u; void *data; - SIZE_T size; + DWORD size; };
static inline struct asyncdataloader *impl_from_ID3DX10DataLoader(ID3DX10DataLoader *iface) @@ -169,27 +169,74 @@ static const ID3DX10DataLoaderVtbl filedataloadervtbl = filedataloader_Destroy };
+static HRESULT load_resource_initA(HMODULE module, const char *resource, HRSRC *rsrc) +{ + if (!(*rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA))) + *rsrc = FindResourceA(module, resource, (const char *)RT_BITMAP); + if (!*rsrc) + { + WARN("Failed to find resource.\n"); + return D3DX10_ERR_INVALID_DATA; + } + return S_OK; +} + +static HRESULT load_resource_initW(HMODULE module, const WCHAR *resource, HRSRC *rsrc) +{ + if (!(*rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))) + *rsrc = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP); + if (!*rsrc) + { + WARN("Failed to find resource.\n"); + return D3DX10_ERR_INVALID_DATA; + } + return S_OK; +} + +static HRESULT load_resource(HMODULE module, HRSRC rsrc, void **data, DWORD *size) +{ + HGLOBAL hglobal; + + if (!(*size = SizeofResource(module, rsrc))) + return D3DX10_ERR_INVALID_DATA; + if (!(hglobal = LoadResource(module, rsrc))) + return D3DX10_ERR_INVALID_DATA; + if (!(*data = LockResource(hglobal))) + return D3DX10_ERR_INVALID_DATA; + return S_OK; +} + +HRESULT load_resourceA(HMODULE module, const char *resource, void **data, DWORD *size) +{ + HRESULT hr; + HRSRC rsrc; + + if (FAILED((hr = load_resource_initA(module, resource, &rsrc)))) + return hr; + return load_resource(module, rsrc, data, size); +} + +HRESULT load_resourceW(HMODULE module, const WCHAR *resource, void **data, DWORD *size) +{ + HRESULT hr; + HRSRC rsrc; + + if ((FAILED(hr = load_resource_initW(module, resource, &rsrc)))) + return hr; + return load_resource(module, rsrc, data, size); +} + static HRESULT WINAPI resourcedataloader_Load(ID3DX10DataLoader *iface) { struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface); - HGLOBAL hglobal;
TRACE("iface %p.\n", iface);
if (loader->data) return S_OK;
- hglobal = LoadResource(loader->u.resource.module, loader->u.resource.rsrc); - if (!hglobal) - { - WARN("Failed to load resource.\n"); - return E_FAIL; - } - - loader->data = LockResource(hglobal); - loader->size = SizeofResource(loader->u.resource.module, loader->u.resource.rsrc); - - return S_OK; + return load_resource(loader->u.resource.module, loader->u.resource.rsrc, + &loader->data, &loader->size); }
static HRESULT WINAPI resourcedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *size) @@ -344,6 +391,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *reso { struct asyncdataloader *object; HRSRC rsrc; + HRESULT hr;
TRACE("module %p, resource %s, loader %p.\n", module, debugstr_a(resource), loader);
@@ -354,13 +402,10 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *reso if (!object) return E_OUTOFMEMORY;
- if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA))) - rsrc = FindResourceA(module, resource, (const char *)RT_BITMAP); - if (!rsrc) + if (FAILED((hr = load_resource_initA(module, resource, &rsrc)))) { - WARN("Failed to find resource.\n"); free(object); - return D3DX10_ERR_INVALID_DATA; + return hr; }
object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl; @@ -378,6 +423,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res { struct asyncdataloader *object; HRSRC rsrc; + HRESULT hr;
TRACE("module %p, resource %s, loader %p.\n", module, debugstr_w(resource), loader);
@@ -388,13 +434,10 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res if (!object) return E_OUTOFMEMORY;
- if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))) - rsrc = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP); - if (!rsrc) + if (FAILED((hr = load_resource_initW(module, resource, &rsrc)))) { - WARN("Failed to find resource.\n"); free(object); - return D3DX10_ERR_INVALID_DATA; + return hr; }
object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl; diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index 9ae3fe93f85..c66eb679a8f 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -24,6 +24,7 @@ #include "d3d10_1.h" #include "d3dx10.h" #include "d3dcompiler.h" +#include "dxhelpers.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
@@ -123,32 +124,12 @@ HRESULT WINAPI D3DX10CreateEffectFromFileA(const char *filename, const D3D10_SHA return hr; }
-static HRESULT get_resource_data(HMODULE module, HRSRC resinfo, void **buffer, DWORD *length) -{ - HGLOBAL resource; - - *length = SizeofResource(module, resinfo); - if (!*length) - return D3DX10_ERR_INVALID_DATA; - - resource = LoadResource(module, resinfo); - if (!resource) - return D3DX10_ERR_INVALID_DATA; - - *buffer = LockResource(resource); - if (!*buffer) - return D3DX10_ERR_INVALID_DATA; - - return S_OK; -} - HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resource_name, const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, ID3D10Blob **errors, HRESULT *hresult) { - HRSRC resinfo; void *data; DWORD size; HRESULT hr; @@ -159,10 +140,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resou defines, include, debugstr_a(profile), shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult);
- if (!(resinfo = FindResourceA(module, resource_name, (const char *)RT_RCDATA))) - return D3DX10_ERR_INVALID_DATA; - - if (FAILED(hr = get_resource_data(module, resinfo, &data, &size))) + hr = load_resourceA(module, resource_name, &data, &size); + if (FAILED(hr)) return hr;
return D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile, @@ -176,7 +155,6 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso ID3D10Blob **errors, HRESULT *hresult) { char *filename = NULL; - HRSRC resinfo; void *data; DWORD size; HRESULT hr; @@ -188,10 +166,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso defines, include, debugstr_a(profile), shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult);
- if (!(resinfo = FindResourceW(module, resource_name, (const WCHAR *)RT_RCDATA))) - return D3DX10_ERR_INVALID_DATA; - - if (FAILED(hr = get_resource_data(module, resinfo, &data, &size))) + hr = load_resourceW(module, resource_name, &data, &size); + if (FAILED(hr)) return hr;
if (filenameW) diff --git a/dlls/d3dx10_43/dxhelpers.h b/dlls/d3dx10_43/dxhelpers.h index 9afc9bd901a..d85e5878a18 100644 --- a/dlls/d3dx10_43/dxhelpers.h +++ b/dlls/d3dx10_43/dxhelpers.h @@ -17,3 +17,7 @@ */
extern HRESULT load_file(const WCHAR *path, void **data, DWORD *size) DECLSPEC_HIDDEN; +extern HRESULT load_resourceA(HMODULE module, const char *resource, + void **data, DWORD *size) DECLSPEC_HIDDEN; +extern HRESULT load_resourceW(HMODULE module, const WCHAR *resource, + void **data, DWORD *size) DECLSPEC_HIDDEN; diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index 56258fdd60d..722784fc117 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -292,22 +292,6 @@ static DXGI_FORMAT get_d3dx10_dds_format(DXGI_FORMAT format) return format; }
-static HRESULT load_resource(HMODULE module, HRSRC res_info, void **buffer, DWORD *size) -{ - HGLOBAL resource; - - if (!(*size = SizeofResource(module, res_info))) - return HRESULT_FROM_WIN32(GetLastError()); - - if (!(resource = LoadResource(module, res_info))) - return HRESULT_FROM_WIN32(GetLastError()); - - if (!(*buffer = LockResource(resource))) - return HRESULT_FROM_WIN32(GetLastError()); - - return S_OK; -} - HRESULT WINAPI D3DX10GetImageInfoFromFileA(const char *src_file, ID3DX10ThreadPump *pump, D3DX10_IMAGE_INFO *info, HRESULT *result) { @@ -361,7 +345,6 @@ HRESULT WINAPI D3DX10GetImageInfoFromFileW(const WCHAR *src_file, ID3DX10ThreadP HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resource, ID3DX10ThreadPump *pump, D3DX10_IMAGE_INFO *info, HRESULT *result) { - HRSRC res_info; void *buffer; HRESULT hr; DWORD size; @@ -372,18 +355,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou if (!resource || !info) return D3DX10_ERR_INVALID_DATA;
- res_info = FindResourceA(module, resource, (const char *)RT_RCDATA); - if (!res_info) - { - /* Try loading the resource as bitmap data */ - res_info = FindResourceA(module, resource, (const char *)RT_BITMAP); - if (!res_info) - return D3DX10_ERR_INVALID_DATA; - } - - hr = load_resource(module, res_info, &buffer, &size); + hr = load_resourceA(module, resource, &buffer, &size); if (FAILED(hr)) - return D3DX10_ERR_INVALID_DATA; + return hr;
return D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result); } @@ -391,7 +365,6 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *resource, ID3DX10ThreadPump *pump, D3DX10_IMAGE_INFO *info, HRESULT *result) { - HRSRC res_info; void *buffer; HRESULT hr; DWORD size; @@ -402,18 +375,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *reso if (!resource || !info) return D3DX10_ERR_INVALID_DATA;
- res_info = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA); - if (!res_info) - { - /* Try loading the resource as bitmap data */ - res_info = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP); - if (!res_info) - return D3DX10_ERR_INVALID_DATA; - } - - hr = load_resource(module, res_info, &buffer, &size); + hr = load_resourceW(module, resource, &buffer, &size); if (FAILED(hr)) - return D3DX10_ERR_INVALID_DATA; + return hr;
return D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result); } @@ -575,7 +539,6 @@ HRESULT WINAPI D3DX10CreateTextureFromFileW(ID3D10Device *device, const WCHAR *s HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE module, const char *resource, D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) { - HRSRC res_info; void *buffer; DWORD size; HRESULT hr; @@ -586,15 +549,9 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE mo if (!resource || !texture) return D3DX10_ERR_INVALID_DATA;
- if (!(res_info = FindResourceA(module, resource, (const char *)RT_RCDATA))) - { - /* Try loading the resource as bitmap data */ - if (!(res_info = FindResourceA(module, resource, (const char *)RT_BITMAP))) - return D3DX10_ERR_INVALID_DATA; - } - - if (FAILED(hr = load_resource(module, res_info, &buffer, &size))) - return D3DX10_ERR_INVALID_DATA; + hr = load_resourceA(module, resource, &buffer, &size); + if (FAILED(hr)) + return hr;
return D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult); } @@ -602,7 +559,6 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE mo HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE module, const WCHAR *resource, D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) { - HRSRC res_info; void *buffer; DWORD size; HRESULT hr; @@ -613,15 +569,9 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE mo if (!resource || !texture) return D3DX10_ERR_INVALID_DATA;
- if (!(res_info = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))) - { - /* Try loading the resource as bitmap data */ - if (!(res_info = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP))) - return D3DX10_ERR_INVALID_DATA; - } - - if (FAILED(hr = load_resource(module, res_info, &buffer, &size))) - return D3DX10_ERR_INVALID_DATA; + hr = load_resourceW(module, resource, &buffer, &size); + if (FAILED(hr)) + return hr;
return D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult); }
From: Piotr Caban piotr@codeweavers.com
--- dlls/d3dx10_43/async.c | 61 ++++++++++++++++++++++++++++++++++++-- dlls/d3dx10_43/dxhelpers.h | 2 ++ dlls/d3dx10_43/texture.c | 27 ++++++++++------- 3 files changed, 77 insertions(+), 13 deletions(-)
diff --git a/dlls/d3dx10_43/async.c b/dlls/d3dx10_43/async.c index 33abd11eed6..0d75a64ff9e 100644 --- a/dlls/d3dx10_43/async.c +++ b/dlls/d3dx10_43/async.c @@ -19,6 +19,7 @@ #include "d3d10_1.h" #include "d3dx10.h" #include "d3dcompiler.h" +#include "dxhelpers.h"
#include "wine/debug.h"
@@ -272,6 +273,48 @@ static const ID3DX10DataLoaderVtbl resourcedataloadervtbl = resourcedataloader_Destroy };
+struct texture_info_processor +{ + ID3DX10DataProcessor ID3DX10DataProcessor_iface; + D3DX10_IMAGE_INFO *info; +}; + +static inline struct texture_info_processor *impl_from_ID3DX10DataProcessor(ID3DX10DataProcessor *iface) +{ + return CONTAINING_RECORD(iface, struct texture_info_processor, ID3DX10DataProcessor_iface); +} + +static HRESULT WINAPI texture_info_processor_Process(ID3DX10DataProcessor *iface, void *data, SIZE_T size) +{ + struct texture_info_processor *processor = impl_from_ID3DX10DataProcessor(iface); + + TRACE("iface %p, data %p, size %Iu.\n", iface, data, size); + return get_image_info(data, size, processor->info); +} + +static HRESULT WINAPI texture_info_processor_CreateDeviceObject(ID3DX10DataProcessor *iface, void **object) +{ + TRACE("iface %p, object %p.\n", iface, object); + return S_OK; +} + +static HRESULT WINAPI texture_info_processor_Destroy(ID3DX10DataProcessor *iface) +{ + struct texture_info_processor *processor = impl_from_ID3DX10DataProcessor(iface); + + TRACE("iface %p.\n", iface); + + free(processor); + return S_OK; +} + +static ID3DX10DataProcessorVtbl texture_info_processor_vtbl = +{ + texture_info_processor_Process, + texture_info_processor_CreateDeviceObject, + texture_info_processor_Destroy +}; + HRESULT WINAPI D3DX10CompileFromMemory(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, ID3DX10ThreadPump *pump, ID3D10Blob **shader, @@ -453,8 +496,22 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res
HRESULT WINAPI D3DX10CreateAsyncTextureInfoProcessor(D3DX10_IMAGE_INFO *info, ID3DX10DataProcessor **processor) { - FIXME("info %p, processor %p stub!\n", info, processor); - return E_NOTIMPL; + struct texture_info_processor *object; + + TRACE("info %p, processor %p.\n", info, processor); + + if (!processor) + return E_INVALIDARG; + + object = malloc(sizeof(*object)); + if (!object) + return E_OUTOFMEMORY; + + object->ID3DX10DataProcessor_iface.lpVtbl = &texture_info_processor_vtbl; + object->info = info; + + *processor = &object->ID3DX10DataProcessor_iface; + return S_OK; }
HRESULT WINAPI D3DX10PreprocessShaderFromMemory(const char *data, SIZE_T data_size, const char *filename, diff --git a/dlls/d3dx10_43/dxhelpers.h b/dlls/d3dx10_43/dxhelpers.h index d85e5878a18..82fe639c2ea 100644 --- a/dlls/d3dx10_43/dxhelpers.h +++ b/dlls/d3dx10_43/dxhelpers.h @@ -21,3 +21,5 @@ extern HRESULT load_resourceA(HMODULE module, const char *resource, void **data, DWORD *size) DECLSPEC_HIDDEN; extern HRESULT load_resourceW(HMODULE module, const WCHAR *resource, void **data, DWORD *size) DECLSPEC_HIDDEN; + +extern HRESULT get_image_info(const void *data, SIZE_T size, D3DX10_IMAGE_INFO *img_info) DECLSPEC_HIDDEN; diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index 722784fc117..3930df3677f 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -382,8 +382,7 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *reso return D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result); }
-HRESULT WINAPI D3DX10GetImageInfoFromMemory(const void *src_data, SIZE_T src_data_size, ID3DX10ThreadPump *pump, - D3DX10_IMAGE_INFO *img_info, HRESULT *hresult) +HRESULT get_image_info(const void *data, SIZE_T size, D3DX10_IMAGE_INFO *img_info) { IWICBitmapFrameDecode *frame = NULL; IWICImagingFactory *factory = NULL; @@ -395,17 +394,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromMemory(const void *src_data, SIZE_T src_dat GUID container_format; HRESULT hr;
- TRACE("src_data %p, src_data_size %Iu, pump %p, img_info %p, hresult %p.\n", - src_data, src_data_size, pump, img_info, hresult); - - if (!src_data || !src_data_size || !img_info) - return E_FAIL; - if (pump) - FIXME("Thread pump is not supported yet.\n"); - WICCreateImagingFactory_Proxy(WINCODEC_SDK_VERSION, &factory); IWICImagingFactory_CreateStream(factory, &stream); - hr = IWICStream_InitializeFromMemory(stream, (BYTE *)src_data, src_data_size); + hr = IWICStream_InitializeFromMemory(stream, (BYTE *)data, size); if (FAILED(hr)) { WARN("Failed to initialize stream.\n"); @@ -486,6 +477,20 @@ end: return S_OK; }
+HRESULT WINAPI D3DX10GetImageInfoFromMemory(const void *src_data, SIZE_T src_data_size, ID3DX10ThreadPump *pump, + D3DX10_IMAGE_INFO *img_info, HRESULT *result) +{ + TRACE("src_data %p, src_data_size %Iu, pump %p, img_info %p, hresult %p.\n", + src_data, src_data_size, pump, img_info, result); + + if (!src_data) + return E_FAIL; + if (pump) + FIXME("Thread pump is not supported yet.\n"); + + return get_image_info(src_data, src_data_size, img_info); +} + HRESULT WINAPI D3DX10CreateTextureFromFileA(ID3D10Device *device, const char *src_file, D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) {
From: Piotr Caban piotr@codeweavers.com
--- dlls/d3dx10_43/tests/d3dx10.c | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
diff --git a/dlls/d3dx10_43/tests/d3dx10.c b/dlls/d3dx10_43/tests/d3dx10.c index 4a734fe0149..a817f346676 100644 --- a/dlls/d3dx10_43/tests/d3dx10.c +++ b/dlls/d3dx10_43/tests/d3dx10.c @@ -1871,6 +1871,48 @@ static void test_D3DX10CreateAsyncResourceLoader(void) ok(hr == D3DX10_ERR_INVALID_DATA, "Got unexpected hr %#x.\n", hr); }
+static void test_D3DX10CreateAsyncTextureInfoProcessor(void) +{ + ID3DX10DataProcessor *dp; + D3DX10_IMAGE_INFO info; + HRESULT hr; + int i; + + CoInitialize(NULL); + + hr = D3DX10CreateAsyncTextureInfoProcessor(NULL, NULL); + ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); + + hr = D3DX10CreateAsyncTextureInfoProcessor(&info, &dp); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + + hr = ID3DX10DataProcessor_Process(dp, (void *)test_image[0].data, 0); + ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); + hr = ID3DX10DataProcessor_Process(dp, NULL, test_image[0].size); + ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); + + for (i = 0; i < ARRAY_SIZE(test_image); ++i) + { + winetest_push_context("Test %u", i); + + hr = ID3DX10DataProcessor_Process(dp, (void *)test_image[i].data, test_image[i].size); + ok(hr == S_OK || broken(hr == E_FAIL && test_image[i].expected_info.ImageFileFormat == D3DX10_IFF_WMP), + "Got unexpected hr %#x.\n", hr); + if (hr == S_OK) + check_image_info(&info, test_image + i, __LINE__); + + winetest_pop_context(); + } + + hr = ID3DX10DataProcessor_CreateDeviceObject(dp, NULL); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + + hr = ID3DX10DataProcessor_Destroy(dp); + ok(hr == S_OK, "Got unexpected hr %#x.\n", hr); + + CoUninitialize(); +} + static void test_get_image_info(void) { static const WCHAR test_resource_name[] = L"resource.data"; @@ -3273,6 +3315,7 @@ START_TEST(d3dx10) test_D3DX10CreateAsyncMemoryLoader(); test_D3DX10CreateAsyncFileLoader(); test_D3DX10CreateAsyncResourceLoader(); + test_D3DX10CreateAsyncTextureInfoProcessor(); test_get_image_info(); test_create_texture(); test_font();