d3dx10: Implement D3DX10CreateTextureFromFile{A,W}.

Signed-off-by: Ziqing Hui <zhui@codeweavers.com>
Signed-off-by: Matteo Bruni <mbruni@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Ziqing Hui 2021-11-04 19:28:47 +08:00 committed by Alexandre Julliard
parent 8dc6987ba5
commit 81bc256685
2 changed files with 40 additions and 9 deletions

View File

@ -2034,8 +2034,6 @@ static void test_create_texture(void)
/* D3DX10CreateTextureFromFile tests */ /* D3DX10CreateTextureFromFile tests */
todo_wine
{
hr = D3DX10CreateTextureFromFileW(device, NULL, NULL, NULL, &resource, NULL); hr = D3DX10CreateTextureFromFileW(device, NULL, NULL, NULL, &resource, NULL);
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = D3DX10CreateTextureFromFileW(device, L"deadbeef", NULL, NULL, &resource, NULL); hr = D3DX10CreateTextureFromFileW(device, L"deadbeef", NULL, NULL, &resource, NULL);
@ -2044,7 +2042,6 @@ static void test_create_texture(void)
ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr); ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
hr = D3DX10CreateTextureFromFileA(device, "deadbeef", NULL, NULL, &resource, NULL); hr = D3DX10CreateTextureFromFileA(device, "deadbeef", NULL, NULL, &resource, NULL);
ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#x.\n", hr); ok(hr == D3D10_ERROR_FILE_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
}
for (i = 0; i < ARRAY_SIZE(test_image); ++i) for (i = 0; i < ARRAY_SIZE(test_image); ++i)
{ {
@ -2052,7 +2049,7 @@ static void test_create_texture(void)
create_file(test_filename, test_image[i].data, test_image[i].size, path); create_file(test_filename, test_image[i].data, test_image[i].size, path);
hr = D3DX10CreateTextureFromFileW(device, path, NULL, NULL, &resource, NULL); hr = D3DX10CreateTextureFromFileW(device, path, NULL, NULL, &resource, NULL);
todo_wine todo_wine_if(test_image[i].expected_info.MiscFlags & D3D10_RESOURCE_MISC_TEXTURECUBE)
ok(hr == S_OK || broken(hr == E_FAIL && test_image[i].expected_info.ImageFileFormat == D3DX10_IFF_WMP), ok(hr == S_OK || broken(hr == E_FAIL && test_image[i].expected_info.ImageFileFormat == D3DX10_IFF_WMP),
"Got unexpected hr %#x.\n", hr); "Got unexpected hr %#x.\n", hr);
if (hr == S_OK) if (hr == S_OK)
@ -2063,7 +2060,7 @@ static void test_create_texture(void)
} }
hr = D3DX10CreateTextureFromFileA(device, get_str_a(path), NULL, NULL, &resource, NULL); hr = D3DX10CreateTextureFromFileA(device, get_str_a(path), NULL, NULL, &resource, NULL);
todo_wine todo_wine_if(test_image[i].expected_info.MiscFlags & D3D10_RESOURCE_MISC_TEXTURECUBE)
ok(hr == S_OK || broken(hr == E_FAIL && test_image[i].expected_info.ImageFileFormat == D3DX10_IFF_WMP), ok(hr == S_OK || broken(hr == E_FAIL && test_image[i].expected_info.ImageFileFormat == D3DX10_IFF_WMP),
"Got unexpected hr %#x.\n", hr); "Got unexpected hr %#x.\n", hr);
if (hr == S_OK) if (hr == S_OK)

View File

@ -576,17 +576,51 @@ end:
HRESULT WINAPI D3DX10CreateTextureFromFileA(ID3D10Device *device, const char *src_file, HRESULT WINAPI D3DX10CreateTextureFromFileA(ID3D10Device *device, const char *src_file,
D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult)
{ {
FIXME("device %p, src_file %s, load_info %p, pump %p, texture %p, hresult %p stub!\n", WCHAR *buffer;
int str_len;
HRESULT hr;
TRACE("device %p, src_file %s, load_info %p, pump %p, texture %p, hresult %p.\n",
device, debugstr_a(src_file), load_info, pump, texture, hresult); device, debugstr_a(src_file), load_info, pump, texture, hresult);
return E_NOTIMPL;
if (!src_file || !texture)
return E_FAIL;
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))))
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);
return hr;
} }
HRESULT WINAPI D3DX10CreateTextureFromFileW(ID3D10Device *device, const WCHAR *src_file, HRESULT WINAPI D3DX10CreateTextureFromFileW(ID3D10Device *device, const WCHAR *src_file,
D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult)
{ {
FIXME("device %p, src_file %s, load_info %p, pump %p, texture %p, hresult %p stub!\n", void *buffer = NULL;
DWORD size = 0;
HRESULT hr;
TRACE("device %p, src_file %s, load_info %p, pump %p, texture %p, hresult %p.\n",
device, debugstr_w(src_file), load_info, pump, texture, hresult); device, debugstr_w(src_file), load_info, pump, texture, hresult);
return E_NOTIMPL;
if (!src_file || !texture)
return E_FAIL;
if (FAILED(load_file(src_file, &buffer, &size)))
return D3D10_ERROR_FILE_NOT_FOUND;
hr = D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult);
heap_free(buffer);
return hr;
} }
HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE module, const char *resource, HRESULT WINAPI D3DX10CreateTextureFromResourceA(ID3D10Device *device, HMODULE module, const char *resource,