Commit a2521a90 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

d3dx10: Share code for resource data loading.

parent 099fb5fa
...@@ -41,7 +41,7 @@ struct asyncdataloader ...@@ -41,7 +41,7 @@ struct asyncdataloader
} resource; } resource;
} u; } u;
void *data; void *data;
SIZE_T size; DWORD size;
}; };
static inline struct asyncdataloader *impl_from_ID3DX10DataLoader(ID3DX10DataLoader *iface) static inline struct asyncdataloader *impl_from_ID3DX10DataLoader(ID3DX10DataLoader *iface)
...@@ -169,27 +169,74 @@ static const ID3DX10DataLoaderVtbl filedataloadervtbl = ...@@ -169,27 +169,74 @@ static const ID3DX10DataLoaderVtbl filedataloadervtbl =
filedataloader_Destroy 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) static HRESULT WINAPI resourcedataloader_Load(ID3DX10DataLoader *iface)
{ {
struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface); struct asyncdataloader *loader = impl_from_ID3DX10DataLoader(iface);
HGLOBAL hglobal;
TRACE("iface %p.\n", iface); TRACE("iface %p.\n", iface);
if (loader->data) if (loader->data)
return S_OK; return S_OK;
hglobal = LoadResource(loader->u.resource.module, loader->u.resource.rsrc); return load_resource(loader->u.resource.module, loader->u.resource.rsrc,
if (!hglobal) &loader->data, &loader->size);
{
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;
} }
static HRESULT WINAPI resourcedataloader_Decompress(ID3DX10DataLoader *iface, void **data, SIZE_T *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 ...@@ -344,6 +391,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *reso
{ {
struct asyncdataloader *object; struct asyncdataloader *object;
HRSRC rsrc; HRSRC rsrc;
HRESULT hr;
TRACE("module %p, resource %s, loader %p.\n", module, debugstr_a(resource), loader); 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 ...@@ -354,13 +402,10 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderA(HMODULE module, const char *reso
if (!object) if (!object)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if (!(rsrc = FindResourceA(module, resource, (const char *)RT_RCDATA))) if (FAILED((hr = load_resource_initA(module, resource, &rsrc))))
rsrc = FindResourceA(module, resource, (const char *)RT_BITMAP);
if (!rsrc)
{ {
WARN("Failed to find resource.\n");
free(object); free(object);
return D3DX10_ERR_INVALID_DATA; return hr;
} }
object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl; object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
...@@ -378,6 +423,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res ...@@ -378,6 +423,7 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res
{ {
struct asyncdataloader *object; struct asyncdataloader *object;
HRSRC rsrc; HRSRC rsrc;
HRESULT hr;
TRACE("module %p, resource %s, loader %p.\n", module, debugstr_w(resource), loader); 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 ...@@ -388,13 +434,10 @@ HRESULT WINAPI D3DX10CreateAsyncResourceLoaderW(HMODULE module, const WCHAR *res
if (!object) if (!object)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
if (!(rsrc = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))) if (FAILED((hr = load_resource_initW(module, resource, &rsrc))))
rsrc = FindResourceW(module, resource, (const WCHAR *)RT_BITMAP);
if (!rsrc)
{ {
WARN("Failed to find resource.\n");
free(object); free(object);
return D3DX10_ERR_INVALID_DATA; return hr;
} }
object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl; object->ID3DX10DataLoader_iface.lpVtbl = &resourcedataloadervtbl;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "d3d10_1.h" #include "d3d10_1.h"
#include "d3dx10.h" #include "d3dx10.h"
#include "d3dcompiler.h" #include "d3dcompiler.h"
#include "dxhelpers.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3dx); WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
...@@ -123,32 +124,12 @@ HRESULT WINAPI D3DX10CreateEffectFromFileA(const char *filename, const D3D10_SHA ...@@ -123,32 +124,12 @@ HRESULT WINAPI D3DX10CreateEffectFromFileA(const char *filename, const D3D10_SHA
return hr; 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, HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resource_name,
const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include,
const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device, const char *profile, UINT shader_flags, UINT effect_flags, ID3D10Device *device,
ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect, ID3D10EffectPool *effect_pool, ID3DX10ThreadPump *pump, ID3D10Effect **effect,
ID3D10Blob **errors, HRESULT *hresult) ID3D10Blob **errors, HRESULT *hresult)
{ {
HRSRC resinfo;
void *data; void *data;
DWORD size; DWORD size;
HRESULT hr; HRESULT hr;
...@@ -159,10 +140,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resou ...@@ -159,10 +140,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceA(HMODULE module, const char *resou
defines, include, debugstr_a(profile), shader_flags, effect_flags, defines, include, debugstr_a(profile), shader_flags, effect_flags,
device, effect_pool, pump, effect, errors, hresult); device, effect_pool, pump, effect, errors, hresult);
if (!(resinfo = FindResourceA(module, resource_name, (const char *)RT_RCDATA))) hr = load_resourceA(module, resource_name, &data, &size);
return D3DX10_ERR_INVALID_DATA; if (FAILED(hr))
if (FAILED(hr = get_resource_data(module, resinfo, &data, &size)))
return hr; return hr;
return D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile, return D3DX10CreateEffectFromMemory(data, size, filename, defines, include, profile,
...@@ -176,7 +155,6 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso ...@@ -176,7 +155,6 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso
ID3D10Blob **errors, HRESULT *hresult) ID3D10Blob **errors, HRESULT *hresult)
{ {
char *filename = NULL; char *filename = NULL;
HRSRC resinfo;
void *data; void *data;
DWORD size; DWORD size;
HRESULT hr; HRESULT hr;
...@@ -188,10 +166,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso ...@@ -188,10 +166,8 @@ HRESULT WINAPI D3DX10CreateEffectFromResourceW(HMODULE module, const WCHAR *reso
defines, include, debugstr_a(profile), shader_flags, effect_flags, defines, include, debugstr_a(profile), shader_flags, effect_flags,
device, effect_pool, pump, effect, errors, hresult); device, effect_pool, pump, effect, errors, hresult);
if (!(resinfo = FindResourceW(module, resource_name, (const WCHAR *)RT_RCDATA))) hr = load_resourceW(module, resource_name, &data, &size);
return D3DX10_ERR_INVALID_DATA; if (FAILED(hr))
if (FAILED(hr = get_resource_data(module, resinfo, &data, &size)))
return hr; return hr;
if (filenameW) if (filenameW)
......
...@@ -17,3 +17,7 @@ ...@@ -17,3 +17,7 @@
*/ */
extern HRESULT load_file(const WCHAR *path, void **data, DWORD *size) DECLSPEC_HIDDEN; 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) ...@@ -292,22 +292,6 @@ static DXGI_FORMAT get_d3dx10_dds_format(DXGI_FORMAT format)
return 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 WINAPI D3DX10GetImageInfoFromFileA(const char *src_file, ID3DX10ThreadPump *pump, D3DX10_IMAGE_INFO *info,
HRESULT *result) HRESULT *result)
{ {
...@@ -361,7 +345,6 @@ HRESULT WINAPI D3DX10GetImageInfoFromFileW(const WCHAR *src_file, ID3DX10ThreadP ...@@ -361,7 +345,6 @@ HRESULT WINAPI D3DX10GetImageInfoFromFileW(const WCHAR *src_file, ID3DX10ThreadP
HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resource, ID3DX10ThreadPump *pump, HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resource, ID3DX10ThreadPump *pump,
D3DX10_IMAGE_INFO *info, HRESULT *result) D3DX10_IMAGE_INFO *info, HRESULT *result)
{ {
HRSRC res_info;
void *buffer; void *buffer;
HRESULT hr; HRESULT hr;
DWORD size; DWORD size;
...@@ -372,18 +355,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou ...@@ -372,18 +355,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou
if (!resource || !info) if (!resource || !info)
return D3DX10_ERR_INVALID_DATA; return D3DX10_ERR_INVALID_DATA;
res_info = FindResourceA(module, resource, (const char *)RT_RCDATA); hr = load_resourceA(module, resource, &buffer, &size);
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);
if (FAILED(hr)) if (FAILED(hr))
return D3DX10_ERR_INVALID_DATA; return hr;
return D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result); return D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result);
} }
...@@ -391,7 +365,6 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou ...@@ -391,7 +365,6 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceA(HMODULE module, const char *resou
HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *resource, ID3DX10ThreadPump *pump, HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *resource, ID3DX10ThreadPump *pump,
D3DX10_IMAGE_INFO *info, HRESULT *result) D3DX10_IMAGE_INFO *info, HRESULT *result)
{ {
HRSRC res_info;
void *buffer; void *buffer;
HRESULT hr; HRESULT hr;
DWORD size; DWORD size;
...@@ -402,18 +375,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *reso ...@@ -402,18 +375,9 @@ HRESULT WINAPI D3DX10GetImageInfoFromResourceW(HMODULE module, const WCHAR *reso
if (!resource || !info) if (!resource || !info)
return D3DX10_ERR_INVALID_DATA; return D3DX10_ERR_INVALID_DATA;
res_info = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA); hr = load_resourceW(module, resource, &buffer, &size);
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);
if (FAILED(hr)) if (FAILED(hr))
return D3DX10_ERR_INVALID_DATA; return hr;
return D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result); return D3DX10GetImageInfoFromMemory(buffer, size, pump, info, result);
} }
...@@ -575,7 +539,6 @@ HRESULT WINAPI D3DX10CreateTextureFromFileW(ID3D10Device *device, const WCHAR *s ...@@ -575,7 +539,6 @@ HRESULT WINAPI D3DX10CreateTextureFromFileW(ID3D10Device *device, const WCHAR *s
HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE module, const char *resource, HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE module, const char *resource,
D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult)
{ {
HRSRC res_info;
void *buffer; void *buffer;
DWORD size; DWORD size;
HRESULT hr; HRESULT hr;
...@@ -586,15 +549,9 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE mo ...@@ -586,15 +549,9 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE mo
if (!resource || !texture) if (!resource || !texture)
return D3DX10_ERR_INVALID_DATA; return D3DX10_ERR_INVALID_DATA;
if (!(res_info = FindResourceA(module, resource, (const char *)RT_RCDATA))) hr = load_resourceA(module, resource, &buffer, &size);
{ if (FAILED(hr))
/* Try loading the resource as bitmap data */ return hr;
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;
return D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult); return D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult);
} }
...@@ -602,7 +559,6 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE mo ...@@ -602,7 +559,6 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE mo
HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE module, const WCHAR *resource, HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE module, const WCHAR *resource,
D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult)
{ {
HRSRC res_info;
void *buffer; void *buffer;
DWORD size; DWORD size;
HRESULT hr; HRESULT hr;
...@@ -613,15 +569,9 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE mo ...@@ -613,15 +569,9 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE mo
if (!resource || !texture) if (!resource || !texture)
return D3DX10_ERR_INVALID_DATA; return D3DX10_ERR_INVALID_DATA;
if (!(res_info = FindResourceW(module, resource, (const WCHAR *)RT_RCDATA))) hr = load_resourceW(module, resource, &buffer, &size);
{ if (FAILED(hr))
/* Try loading the resource as bitmap data */ return hr;
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;
return D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult); return D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment