mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-15 22:59:34 +00:00
d3dx10: Share code for resource data loading.
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
This commit is contained in:
parent
099fb5fad1
commit
a2521a90f4
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue