From: Connor McAdams <cmcadams@codeweavers.com> Signed-off-by: Connor McAdams <cmcadams@codeweavers.com> --- dlls/d3dx10_43/async.c | 94 ++++-------------------------------- dlls/d3dx10_43/compiler.c | 8 +-- dlls/d3dx10_43/dxhelpers.h | 4 -- dlls/d3dx10_43/texture.c | 16 +++--- dlls/d3dx9_36/d3dx_helpers.c | 91 ++++++++++++++++++++++++++++++++++ dlls/d3dx9_36/d3dx_helpers.h | 10 ++++ 6 files changed, 122 insertions(+), 101 deletions(-) diff --git a/dlls/d3dx10_43/async.c b/dlls/d3dx10_43/async.c index e2cd14a7736..0c72bfd7226 100644 --- a/dlls/d3dx10_43/async.c +++ b/dlls/d3dx10_43/async.c @@ -45,7 +45,7 @@ struct asyncdataloader } resource; } u; void *data; - DWORD size; + uint32_t size; }; static inline struct asyncdataloader *impl_from_ID3DX10DataLoader(ID3DX10DataLoader *iface) @@ -90,32 +90,13 @@ static const ID3DX10DataLoaderVtbl memorydataloadervtbl = HRESULT load_file(const WCHAR *path, void **data, DWORD *size) { - DWORD read_len; - HANDLE file; - BOOL ret; + uint32_t file_size; + HRESULT hr; - file = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (file == INVALID_HANDLE_VALUE) + if ((hr = d3dx_load_file(path, data, &file_size)) == ERROR_FILE_NOT_FOUND) return D3D10_ERROR_FILE_NOT_FOUND; - - *size = GetFileSize(file, NULL); - *data = malloc(*size); - if (!*data) - { - CloseHandle(file); - return E_OUTOFMEMORY; - } - - ret = ReadFile(file, *data, *size, &read_len, NULL); - CloseHandle(file); - if (!ret || read_len != *size) - { - WARN("Failed to read file contents.\n"); - free(*data); - return E_FAIL; - } - return S_OK; + *size = file_size; + return hr; } static HRESULT WINAPI filedataloader_Load(ID3DX10DataLoader *iface) @@ -173,63 +154,6 @@ 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); @@ -239,7 +163,7 @@ static HRESULT WINAPI resourcedataloader_Load(ID3DX10DataLoader *iface) if (loader->data) return S_OK; - return load_resource(loader->u.resource.module, loader->u.resource.rsrc, + return d3dx_load_resource(loader->u.resource.module, loader->u.resource.rsrc, &loader->data, &loader->size); } @@ -514,7 +438,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *reso if (!object) return E_OUTOFMEMORY; - if (FAILED((hr = load_resource_initA(module, resource, &rsrc)))) + if (FAILED((hr = d3dx_load_resource_init_a(module, resource, &rsrc)))) { free(object); return hr; @@ -546,7 +470,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res if (!object) return E_OUTOFMEMORY; - if (FAILED((hr = load_resource_initW(module, resource, &rsrc)))) + if (FAILED((hr = d3dx_load_resource_init_w(module, resource, &rsrc)))) { free(object); return hr; diff --git a/dlls/d3dx10_43/compiler.c b/dlls/d3dx10_43/compiler.c index 281dae329e5..1c056916903 100644 --- a/dlls/d3dx10_43/compiler.c +++ b/dlls/d3dx10_43/compiler.c @@ -162,8 +162,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resou ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, ID3D10Blob **errors, HRESULT *hresult) { + uint32_t size; void *data; - DWORD size; HRESULT hr; TRACE("module %p, resource_name %s, filename %s, defines %p, include %p, profile %s, " @@ -172,7 +172,7 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resou defines, include, debugstr_a(profile), shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); - hr = load_resourceA(module, resource_name, &data, &size); + hr = d3dx_load_resource_a(module, resource_name, &data, &size); if (FAILED(hr)) return hr; @@ -187,8 +187,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso ID3D10Blob **errors, HRESULT *hresult) { char *filename = NULL; + uint32_t size; void *data; - DWORD size; HRESULT hr; int len; @@ -198,7 +198,7 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso defines, include, debugstr_a(profile), shader_flags, effect_flags, device, effect_pool, pump, effect, errors, hresult); - hr = load_resourceW(module, resource_name, &data, &size); + hr = d3dx_load_resource_w(module, resource_name, &data, &size); if (FAILED(hr)) return hr; diff --git a/dlls/d3dx10_43/dxhelpers.h b/dlls/d3dx10_43/dxhelpers.h index 8047d354749..2311bb31242 100644 --- a/dlls/d3dx10_43/dxhelpers.h +++ b/dlls/d3dx10_43/dxhelpers.h @@ -19,10 +19,6 @@ #include "d3dx_helpers.h" extern HRESULT load_file(const WCHAR *path, void **data, DWORD *size); -extern HRESULT load_resourceA(HMODULE module, const char *resource, - void **data, DWORD *size); -extern HRESULT load_resourceW(HMODULE module, const WCHAR *resource, - void **data, DWORD *size); extern HRESULT get_image_info(const void *data, SIZE_T size, D3DX10_IMAGE_INFO *img_info); diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index fb6bd5ae489..aa173e3f004 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -245,9 +245,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromFileW(const WCHAR *src_file, ID3DX10ThreadP HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resource, ID3DX10ThreadPump *pump, D3DX10_IMAGE_INFO *info, HRESULT *result) { + uint32_t size; void *buffer; HRESULT hr; - DWORD size; TRACE("module %p, resource %s, pump %p, info %p, result %p.\n", module, debugstr_a(resource), pump, info, result); @@ -272,7 +272,7 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou return hr; } - if (FAILED((hr = load_resourceA(module, resource, &buffer, &size)))) + if (FAILED((hr = d3dx_load_resource_a(module, resource, &buffer, &size)))) return hr; hr = get_image_info(buffer, size, info); if (result) @@ -283,9 +283,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *resource, ID3DX10ThreadPump *pump, D3DX10_IMAGE_INFO *info, HRESULT *result) { + uint32_t size; void *buffer; HRESULT hr; - DWORD size; TRACE("module %p, resource %s, pump %p, info %p, result %p.\n", module, debugstr_w(resource), pump, info, result); @@ -310,7 +310,7 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *reso return hr; } - if (FAILED((hr = load_resourceW(module, resource, &buffer, &size)))) + if (FAILED((hr = d3dx_load_resource_w(module, resource, &buffer, &size)))) return hr; hr = get_image_info(buffer, size, info); if (result) @@ -532,8 +532,8 @@ 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) { + uint32_t size; void *buffer; - DWORD size; HRESULT hr; TRACE("device %p, module %p, resource %s, load_info %p, pump %p, texture %p, hresult %p.\n", @@ -562,7 +562,7 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE mo return hr; } - if (FAILED((hr = load_resourceA(module, resource, &buffer, &size)))) + if (FAILED((hr = d3dx_load_resource_a(module, resource, &buffer, &size)))) return hr; hr = create_texture(device, buffer, size, load_info, texture); if (hresult) @@ -573,8 +573,8 @@ 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) { + uint32_t size; void *buffer; - DWORD size; HRESULT hr; TRACE("device %p, module %p, resource %s, load_info %p, pump %p, texture %p, hresult %p.\n", @@ -603,7 +603,7 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE mo return hr; } - if (FAILED((hr = load_resourceW(module, resource, &buffer, &size)))) + if (FAILED((hr = d3dx_load_resource_w(module, resource, &buffer, &size)))) return hr; hr = create_texture(device, buffer, size, load_info, texture); if (hresult) diff --git a/dlls/d3dx9_36/d3dx_helpers.c b/dlls/d3dx9_36/d3dx_helpers.c index 684bc50e5eb..4c0f49be1d4 100644 --- a/dlls/d3dx9_36/d3dx_helpers.c +++ b/dlls/d3dx9_36/d3dx_helpers.c @@ -3368,3 +3368,94 @@ exit: free(sub_rsrc_data); return hr; } + +/* + * File/resource loading helper functions. + */ +HRESULT d3dx_load_file(const WCHAR *path, void **data, uint32_t *size) +{ + DWORD read_len; + HANDLE file; + BOOL ret; + + file = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); + if (file == INVALID_HANDLE_VALUE) + return ERROR_FILE_NOT_FOUND; + + *size = GetFileSize(file, NULL); + *data = malloc(*size); + if (!*data) + { + CloseHandle(file); + return E_OUTOFMEMORY; + } + + ret = ReadFile(file, *data, *size, &read_len, NULL); + CloseHandle(file); + if (!ret || read_len != *size) + { + WARN("Failed to read file contents.\n"); + free(*data); + return E_FAIL; + } + + return S_OK; +} + +HRESULT d3dx_load_resource_init_a(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 D3DXERR_INVALIDDATA; + } + return S_OK; +} + +HRESULT d3dx_load_resource_init_w(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 D3DXERR_INVALIDDATA; + } + return S_OK; +} + +HRESULT d3dx_load_resource(HMODULE module, HRSRC rsrc, void **data, uint32_t *size) +{ + HGLOBAL hglobal; + + if (!(*size = SizeofResource(module, rsrc))) + return D3DXERR_INVALIDDATA; + if (!(hglobal = LoadResource(module, rsrc))) + return D3DXERR_INVALIDDATA; + if (!(*data = LockResource(hglobal))) + return D3DXERR_INVALIDDATA; + return S_OK; +} + +HRESULT d3dx_load_resource_a(HMODULE module, const char *resource, void **data, uint32_t *size) +{ + HRESULT hr; + HRSRC rsrc; + + if (FAILED((hr = d3dx_load_resource_init_a(module, resource, &rsrc)))) + return hr; + return d3dx_load_resource(module, rsrc, data, size); +} + +HRESULT d3dx_load_resource_w(HMODULE module, const WCHAR *resource, void **data, uint32_t *size) +{ + HRESULT hr; + HRSRC rsrc; + + if ((FAILED(hr = d3dx_load_resource_init_w(module, resource, &rsrc)))) + return hr; + return d3dx_load_resource(module, rsrc, data, size); +} diff --git a/dlls/d3dx9_36/d3dx_helpers.h b/dlls/d3dx9_36/d3dx_helpers.h index d5523cab1ed..9b85149cbaa 100644 --- a/dlls/d3dx9_36/d3dx_helpers.h +++ b/dlls/d3dx9_36/d3dx_helpers.h @@ -458,6 +458,16 @@ HRESULT d3dx_create_subresource_data_for_texture(uint32_t width, uint32_t height uint32_t mip_levels, uint32_t layer_count, const struct pixel_format_desc *fmt_desc, struct d3dx_subresource_data **out_sub_rsrc_data); +/* + * File/resource loading helper functions. + */ +HRESULT d3dx_load_file(const WCHAR *path, void **data, uint32_t *size); +HRESULT d3dx_load_resource_init_a(HMODULE module, const char *resource, HRSRC *rsrc); +HRESULT d3dx_load_resource_init_w(HMODULE module, const WCHAR *resource, HRSRC *rsrc); +HRESULT d3dx_load_resource(HMODULE module, HRSRC rsrc, void **data, uint32_t *size); +HRESULT d3dx_load_resource_a(HMODULE module, const char *resource, void **data, uint32_t *size); +HRESULT d3dx_load_resource_w(HMODULE module, const WCHAR *resource, void **data, uint32_t *size); + /* debug helpers */ const char *debug_d3dx_image_file_format(enum d3dx_image_file_format format); #endif /* __WINE_D3DX_HELPERS_H */ -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9901